1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// Artur Kraska, II UWr

#include <bits/stdc++.h>

#define forr(i, n)                  for(int i=0; i<n; i++)
#define FOREACH(iter, coll)         for(auto iter = coll.begin(); iter != coll.end(); ++iter)
#define FOREACHR(iter, coll)        for(auto iter = coll.rbegin(); iter != coll.rend(); ++iter)
#define lbound(P,R,PRED)            ({typeof(P) X=P,RRR=(R), PPP = P; while(PPP<RRR) {X = (PPP+(RRR-PPP)/2); if(PRED) RRR = X; else PPP = X+1;} PPP;})
#define testy()                     int _tests; scanf("%d", &_tests); FOR(_test, 1, _tests)
#define CLEAR(tab)                  memset(tab, 0, sizeof(tab))
#define CONTAIN(el, coll)           (coll.find(el) != coll.end())
#define FOR(i, a, b)                for(int i=a; i<=b; i++)
#define FORD(i, a, b)               for(int i=a; i>=b; i--)
#define MP                          make_pair
#define PB                          push_back
#define ff                          first
#define ss                          second
#define deb(X)                      X;

#define M 1000000007
#define INF 1000000007LL

using namespace std;

int n, m, numer, res, numbyl;
int zla[1000007];

struct kraw
{
    int nr;
    int id;
};
kraw kr;

struct ww
{
    int nr;
    int low;
    int byl;
    vector <kraw> l;
};
ww tab[1000005];

void go(int v, int o, int id)
{
    tab[v].nr = tab[v].low = numer;
    numer++;

    for(auto k : tab[v].l)
    {
        if(zla[k.id] || k.id == id)   continue;
        if(tab[k.nr].nr == 0)
        {
            go(k.nr, v, k.id);
            tab[v].low = min(tab[v].low, tab[k.nr].low);
        }
        else   tab[v].low = min(tab[v].low, tab[k.nr].nr);
    }

    if(tab[v].low > tab[o].nr)   res++;//, printf("most %d-%d\n", o, v);
}

void punkty_artykulacji()
{
    FOR(i, 1, n)
        tab[i].nr = 0;

    numer = 2;
    tab[1].nr = tab[1].low = 1;

    for(auto k : tab[1].l)
        if(!zla[k.id] && tab[k.nr].nr == 0)
        {
            go(k.nr, 1, k.id);
            numer++;
        }
}

int rozmiar(int nr)
{
    int res = 1;
    tab[nr].byl = numbyl;
    for(auto k : tab[nr].l)
        if(tab[k.nr].byl != numbyl && !zla[k.id])
        {
            res += rozmiar(k.nr);
        }
    return res;
}

int main()
{
    int a, b;

    scanf("%d %d", &n, &m);
    FOR(i, 1, m)
    {
        scanf("%d %d", &a, &b);
        kr.id = i;
        kr.nr = b;
        tab[a].l.PB(kr);
        kr.nr = a;
        tab[b].l.PB(kr);
    }
    /*FOR(i, 1, m)
    {
        cout << "teraz bez krawedzi " << i << endl;
        zla[i] = 1;
        punkty_artykulacji();
        zla[i] = 0;
    }*/
    FOR(i, 1, m)
    {
        numbyl++;
        zla[i] = 1;
        if(rozmiar(1) < n)
        {
//            cout << "wywalenie " << i << " dodaje " << (m-i)*(m-2) << endl;
            res += (m-i)*(m-2);
        }
        else
        {
            FOR(j, i+1, m)
            {
                zla[j] = 1;
                numbyl++;
                if(rozmiar(1) < n)
                {
//                    cout << "wywalenie " << i << " i " << j << " dodaje " << m-2 << endl;
                    res += (m-2);
                }
                else
                {
//                    cout << "liczy mosty" << endl;
                    punkty_artykulacji();
                }
                zla[j] = 0;
            }
        }
        zla[i] = 0;
    }

    printf("%d\n", res/3);

    return 0;
}