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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
#include <bits/stdc++.h>

using namespace std;

#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define RE(i,n) FOR(i,1,n)
#define R(i,n) REP(i,n)
#define PII pair<int,int>
#define LD long double
#define VI vector<int>
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

template<class C> void mini(C&a4, C b4) { a4=min(a4,b4); }
template<class C> void maxi(C&a4, C b4) { a4=max(a4,b4); }

template<class TH> void _dbg(const char *sdbg, TH h){cerr<<sdbg<<"="<<h<<"\n";}
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;cerr<<"="<<h<<",";_dbg(sdbg+1,a...);
}

template<class T> ostream &operator<<(ostream &os, vector<T> V) {
  os<<"[";for(auto vv:V)os<<vv<<",";return os<<"]";
}

template<class L, class R> ostream &operator <<(ostream &os, pair<L,R> PP){
  return os<<"("<<PP.st<<","<<PP.nd<<")";
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

const int P = 1e9 + 7;
int pot(int a,int w){
  int r = 1;
  while(w){
    if(w & 1) r = r * a % P;
    w/=2;
    a = a * a % P;
  }
  return r;
}

struct Testcase {
  int n,m;
  vector<vector<int>> d;
  vector<vector<PII>> cykle;
  vector<int> f;
  vector<int> il;
  vector<PII> hist;

  int find(int v){
    return f[v] == v ? v : find(f[v]);
  }
  
  void uni(int a,int b){
    a = find(a);
    b = find(b);
    if(a == b)return;
    if(il[a] > il[b])swap(a,b);
    f[a] = b;
    il[b] += il[a];
    hist.PB({a,b});
  }
  
  void cof(){
    int a,b;
    tie(a,b) = hist.back();
    hist.pop_back();
    il[b] -= il[a];
    f[a] = a;
  }
  
  vector<PII>stos;
  vector<int>vis;
  int spojne = 0;
  vector<PII> todo;
  vector<int> ord;
  int iord = 1;
  int mosty;
  void dfs(int v,int oj){
    vis[v] = 1;
    ord[v] = iord;
    iord++;
    for(int el:d[v]){
      if(el == oj){
        oj = -1;
        continue;
      }
      
      
      
      if(vis[el]){
        if(ord[el] > ord[v])continue;
        vector<PII> cykl;
        cykl.PB({v,el});
        while(find(v) != find(el)){
          PII pom = stos.back();
          uni(pom.FI,pom.SE);
          cykl.PB(pom);
          stos.pop_back();
        }
        if(SZ(cykl) > 1)
          cykle.PB(cykl);
        else
          todo.PB(cykl[0]);
      }else{
        stos.PB({v,el});
        dfs(el, v);
        if(SZ(stos) && stos.back() == MP(v,el)){
          stos.pop_back();
          m--; // most
          mosty++;
        }
      }
    }
  }
  
  
  int pary = 0;
  vector<int> cz;
  vector<int> naj;
  int icz = 1;
  vector<int> f2;
  vector<int> pier;
  vector<int> ost;
  int find2(int a){
    return f2[a] == a ? a : f2[a] = find2(f2[a]);  
  }
  
  void plecak(int po,int ko){
    if(po + 1 == ko){
      int dl = SZ(cykle[po]);
      vector<int> ss(dl);
      vector<int> dp(dl+1);
      icz ++;
      R(i,dl){
        int kol = ss[i] = find(cykle[po][i].FI);
        if(cz[kol] != icz){
          cz[kol] = icz;
          pier[kol] = i;
          f2[kol] = kol;
        }
        ost[kol] = i;
      }
      debug(ss, pier,icz, cz[0]);
   #define stos fhaifhawuidf
      vector<int> stos;
      R(i,dl-1){
        int kol = find2(ss[i]);
        bool xxx = 0;
        while(SZ(stos) && ost[kol] >= ost[stos.back()]){
          f2[kol] = stos.back();
          mini(pier[stos.back()], pier[kol]);
          maxi(ost[stos.back()], ost[kol]);
          kol = stos.back();
          stos.pop_back();
          if(SZ(stos))stos.back() = find2(stos.back());
          xxx = 1;
        }
        
        if(pier[kol] == i || xxx){
          stos.PB(kol);
        }
        
        debug(stos);
        if(ost[stos.back()] == i){
         
          pary += dp[i+1] = dp[pier[stos.back()]] + 1;
          stos.pop_back();
        }
        debug(pary, stos);
      }
      
      //~ #warning brut
      //~ R(i,dl)R(j,i){
        //~ int cz = 1;
        //~ auto czyw = [&](int a){
          //~ return (a >= i) ^ (a >= j);
        //~ };
        //~ R(ii,dl)R(jj,dl)if(ss[ii] == ss[jj] && czyw(ii) != czyw(jj)){
          //~ cz = 0;
        //~ }
        //~ if(cz)pary += 2;
      //~ }
      //~ 
      return;
    }
    int mm = (po + ko) / 2;
    int pom = SZ(hist);
    for(int i = po; i < mm; i++){
      R(j,SZ(cykle[i])){
        uni(cykle[i][j].FI,cykle[i][j].SE);
      }
    }
    plecak(mm,ko);
    while(SZ(hist) != pom)cof();
    
    for(int i = mm; i < ko; i++){
      R(j,SZ(cykle[i])){
        uni(cykle[i][j].FI,cykle[i][j].SE);
      }
    }
    plecak(po,mm);
    while(SZ(hist) != pom)cof();
    
  }
  
  VI run(int n, vector<pair<int, int>> es) {
    mosty = 0;
    debug(n, m);
    d.resize(n);
    cz.resize(n+1);
    naj.resize(n+1);
    f2.resize(n+1);
    pier.resize(n+1);
    ost.resize(n+1);
    ord.resize(n);
    int petle = 0;
    for (auto e : es) {
      int a,b;
      a = e.st;
      b = e.nd;
      if(a == b){
        petle++;
      }
      a--;b--;
      d[a].PB(b);
      d[b].PB(a);
    }
    vis.resize(n);
    f.resize(n);
    il.resize(n);
    R(i,n){
      f[i] = i;
      il[i] = 1;
    }
    R(i,n){
      if(!vis[i]){
        spojne++;
        dfs(i, -1);
      }
    }
    
    for(auto& pom: cykle)
     debug(pom);
    
    hist.clear();
    R(i,n){
      f[i] = i;
      il[i] = 1;
    }
    for(PII el:todo){
      uni(el.FI,el.SE);
    }
    if(SZ(cykle) != 0){
      plecak(0,SZ(cykle));
    }
    return {spojne, mosty, pary};
    //pary *= 2;
    //debug(spojne, mosty);
    //cout <<  pary << endl;
  }
};
int Choose2(int a) {
  return a * (a - 1) / 2;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  cerr << fixed << setprecision(6);
  
  int n, m;
  cin>>n>>m;
  vector<PII> es;
  RE (i, m) {
    int a, b;
    cin>>a>>b;
    es.PB({a, b});
  }
  int res = 0;
  REP (i, m) {
    vector<PII> bez;
    REP (j, m) {
      if (i == j) { continue; }
      bez.PB(es[j]);
    }
    Testcase tc;
    VI ziom = tc.run(n, bez);
    if (ziom[0] == 2) {
      res += Choose2(m - 1);
    } else {
      res += ziom[2];
      res += Choose2(ziom[1]) + ziom[1] * (m - 1 - ziom[1]);
    }
  }
  assert(res % 3 == 0);
  cout<<res / 3<<endl;
  
}