/* Wang - Zhang - Chin algorithm */ #include <bits/stdc++.h> using namespace std; #pragma GCC optimize("Ofast,unroll-loops") //#pragma GCC target("sse,sse2,mmx,abm") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma,tune=native") typedef long long lld; typedef double lf; typedef long double llf; typedef pair<int,int> pii; typedef pair<lld,lld> pll; #define For(i,s,a) for(int i = (int)s; i < (int)a; ++i) #define rpt(s, it) for(auto it = s.begin(); it != s.end(); ++it) #define brpt(s, it) for(auto it = s.rend(); it != s.rbegin(); --it) #define sz size() #define pb push_back #define eb emplace_back #define ff first #define dd second #define mp make_pair #define all(x) (x).begin(), (x).end() #define ZAPS {int t; scanf("%i", &t); while(t--) solve();} #define make_unique(x) (x).erase( unique(all(x)), (x).end()) template<typename Ta, typename Tb> ostream & operator <<(ostream & os, pair<Ta, Tb> x){ return os << x.ff << " " << x.dd; } const int N = 2e5 + 1; vector<int>c[N]; int low[N], dep[N]; int p[N]; bitset<N>odw; bitset<3001>rea; vector<pii>kr[N]; vector<pii>biglist; void dfs(int x, int d = 0, int par = -1){ dep[x] = d; low[x] = d; odw[x] = 1; bool odwpar = 0; for(auto s : c[x]){ if(!odw[s]) dfs(s, d + 1, x), low[x] = min(low[x], low[s]), p[s] = x; if(s != par || odwpar) low[x] = min(low[x], dep[s]); if(s == par) odwpar = 1; } } int r1, r2, r3; void fft(int x){ if(x < 3001) rea[x] = 1; for(auto s : kr[x]) if(!rea[s.ff] && !(s.dd == r1) && !(s.dd == r2) && !(s.dd == r3)) fft(s.ff); } int dft(int n, int x, int R1, int R2, int R3 = 0){ r1 = R1, r2 = R2, r3 = R3; rea = 0; fft(x); //cout<<r1<<" "<<r2<<" "<<r3<<" "<<rea.count()<<endl; return (int)rea.count() != min(3000, n); } int32_t main(void){ int n, m; scanf("%d%d", &n, &m); For(i, 0, m){ int g,h; scanf("%d%d", &g, &h); c[g].pb(h); c[h].pb(g); } dfs(1); //For(i, 1, n + 1) // cout<<i<<" "<<low[i]<<" "<<dep[i]<<endl; lld wyn = 0; int brct = 0; For(i, 2, n + 1){ if(low[i] > dep[p[i]]) wyn += (lld)(m - 1) * (lld)(m - 2), ++brct; For(j, 0, c[i].sz) if(c[i][j] == p[i]){ swap(c[i][j], c[i][c[i].sz - 1]); break; } } lld wyn2 = 0, wyn3 = 0; //cout<<brct<<endl; int ilee = -1; For(x, 1, n + 1){ For(i, 0, c[x].sz) if(c[x][i] > x){ kr[x].pb(mp(c[x][i], ++ilee)); kr[c[x][i]].pb(mp(x, ilee)); biglist.pb(mp(x, c[x][i])); } } For(i, 0, biglist.sz - 2){ int g = biglist[i].ff; int h = biglist[i].dd; if(dep[g] > dep[h]) swap(g, h); if(dep[g] < low[h]) continue; For(j, i + 1, biglist.sz - 1){ g = biglist[j].ff; h = biglist[j].dd; if(dep[g] > dep[h]) swap(g, h); if(dep[g] < low[h]) continue; For(k, j + 1, biglist.sz){ g = biglist[k].ff; h = biglist[k].dd; if(dep[g] > dep[h]) swap(g, h); if(dep[g] < low[h]) continue; wyn3 += dft(n, 1, i, j, k); //cout<<biglist[i].ff<<" "<<biglist[i].dd<<" "<<biglist[j].ff<<" "<<biglist[j].dd<<" "<<biglist[k].ff<<" "<<biglist[k].dd<<" "<<endl; }}} printf("%lld", wyn3 + wyn / 2ll); } /* 8 11 2 3 4 5 3 1 3 2 5 7 3 6 1 2 3 4 6 5 8 7 7 8 */
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 | /* Wang - Zhang - Chin algorithm */ #include <bits/stdc++.h> using namespace std; #pragma GCC optimize("Ofast,unroll-loops") //#pragma GCC target("sse,sse2,mmx,abm") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma,tune=native") typedef long long lld; typedef double lf; typedef long double llf; typedef pair<int,int> pii; typedef pair<lld,lld> pll; #define For(i,s,a) for(int i = (int)s; i < (int)a; ++i) #define rpt(s, it) for(auto it = s.begin(); it != s.end(); ++it) #define brpt(s, it) for(auto it = s.rend(); it != s.rbegin(); --it) #define sz size() #define pb push_back #define eb emplace_back #define ff first #define dd second #define mp make_pair #define all(x) (x).begin(), (x).end() #define ZAPS {int t; scanf("%i", &t); while(t--) solve();} #define make_unique(x) (x).erase( unique(all(x)), (x).end()) template<typename Ta, typename Tb> ostream & operator <<(ostream & os, pair<Ta, Tb> x){ return os << x.ff << " " << x.dd; } const int N = 2e5 + 1; vector<int>c[N]; int low[N], dep[N]; int p[N]; bitset<N>odw; bitset<3001>rea; vector<pii>kr[N]; vector<pii>biglist; void dfs(int x, int d = 0, int par = -1){ dep[x] = d; low[x] = d; odw[x] = 1; bool odwpar = 0; for(auto s : c[x]){ if(!odw[s]) dfs(s, d + 1, x), low[x] = min(low[x], low[s]), p[s] = x; if(s != par || odwpar) low[x] = min(low[x], dep[s]); if(s == par) odwpar = 1; } } int r1, r2, r3; void fft(int x){ if(x < 3001) rea[x] = 1; for(auto s : kr[x]) if(!rea[s.ff] && !(s.dd == r1) && !(s.dd == r2) && !(s.dd == r3)) fft(s.ff); } int dft(int n, int x, int R1, int R2, int R3 = 0){ r1 = R1, r2 = R2, r3 = R3; rea = 0; fft(x); //cout<<r1<<" "<<r2<<" "<<r3<<" "<<rea.count()<<endl; return (int)rea.count() != min(3000, n); } int32_t main(void){ int n, m; scanf("%d%d", &n, &m); For(i, 0, m){ int g,h; scanf("%d%d", &g, &h); c[g].pb(h); c[h].pb(g); } dfs(1); //For(i, 1, n + 1) // cout<<i<<" "<<low[i]<<" "<<dep[i]<<endl; lld wyn = 0; int brct = 0; For(i, 2, n + 1){ if(low[i] > dep[p[i]]) wyn += (lld)(m - 1) * (lld)(m - 2), ++brct; For(j, 0, c[i].sz) if(c[i][j] == p[i]){ swap(c[i][j], c[i][c[i].sz - 1]); break; } } lld wyn2 = 0, wyn3 = 0; //cout<<brct<<endl; int ilee = -1; For(x, 1, n + 1){ For(i, 0, c[x].sz) if(c[x][i] > x){ kr[x].pb(mp(c[x][i], ++ilee)); kr[c[x][i]].pb(mp(x, ilee)); biglist.pb(mp(x, c[x][i])); } } For(i, 0, biglist.sz - 2){ int g = biglist[i].ff; int h = biglist[i].dd; if(dep[g] > dep[h]) swap(g, h); if(dep[g] < low[h]) continue; For(j, i + 1, biglist.sz - 1){ g = biglist[j].ff; h = biglist[j].dd; if(dep[g] > dep[h]) swap(g, h); if(dep[g] < low[h]) continue; For(k, j + 1, biglist.sz){ g = biglist[k].ff; h = biglist[k].dd; if(dep[g] > dep[h]) swap(g, h); if(dep[g] < low[h]) continue; wyn3 += dft(n, 1, i, j, k); //cout<<biglist[i].ff<<" "<<biglist[i].dd<<" "<<biglist[j].ff<<" "<<biglist[j].dd<<" "<<biglist[k].ff<<" "<<biglist[k].dd<<" "<<endl; }}} printf("%lld", wyn3 + wyn / 2ll); } /* 8 11 2 3 4 5 3 1 3 2 5 7 3 6 1 2 3 4 6 5 8 7 7 8 */ |