#include<cstdio> #include<algorithm> #include<vector> #define S 200007 #define M 500007 using namespace std; typedef long long ll; int n,m; vector < pair < int , int > > V[S]; int z1,z2; ll odp = 0; bool odw[S]; bool odw2[S]; bool marked[M]; int poz[S]; int low[S]; ///vector < int > backk[S]; ///vector < int > normall[S]; void DFS(int x){ odw[x] = 1; for(int i = 0; i < V[x].size();i++){ int a = V[x][i].first; int b = V[x][i].second; if(b != z1 && b != z2 && !odw[a]) DFS(a); } } void DFS2(int x){ odw2[x] = 1; low[x] = poz[x]; for(int i = 0; i < V[x].size();i++){ int a = V[x][i].first; int b = V[x][i].second; if(b != z1 && b != z2){ if(odw2[a]){ if(marked[b] == 1){ }else{ ///backk[x].push_back(a); low[x] = min(low[x],poz[a]); } }else{ ///normall[x].push_back(a); marked[b] = 1; poz[a] = poz[x] + 1; DFS2(a); low[x] = min(low[x],low[a]); if(low[a] >= poz[a]){ if(b > z2){ odp++; } } } } } } void F(int x, int y){ z1 = x; z2 = y; for(int i = 1; i <= n;i++){ odw[i] = odw2[i] = 0; poz[i] = 0; } for(int i = 1; i <= m;i++){ marked[i] = 0; } DFS(1); for(int i = 1; i <= n;i++){ if(odw[i] == 0){ odp += (m-y); return; } } poz[1] = 1; DFS2(1); } int main(void){ int a,b; scanf("%d %d",&n,&m); for(int i = 1; i <= m;i++){ scanf("%d %d",&a,&b); V[a].push_back({b,i}); V[b].push_back({a,i}); } for(int i = 1; i <= m;i++){ for(int j = i+1; j <= m;j++){ F(i,j); } } printf("%lld",odp); return 0; }
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 | #include<cstdio> #include<algorithm> #include<vector> #define S 200007 #define M 500007 using namespace std; typedef long long ll; int n,m; vector < pair < int , int > > V[S]; int z1,z2; ll odp = 0; bool odw[S]; bool odw2[S]; bool marked[M]; int poz[S]; int low[S]; ///vector < int > backk[S]; ///vector < int > normall[S]; void DFS(int x){ odw[x] = 1; for(int i = 0; i < V[x].size();i++){ int a = V[x][i].first; int b = V[x][i].second; if(b != z1 && b != z2 && !odw[a]) DFS(a); } } void DFS2(int x){ odw2[x] = 1; low[x] = poz[x]; for(int i = 0; i < V[x].size();i++){ int a = V[x][i].first; int b = V[x][i].second; if(b != z1 && b != z2){ if(odw2[a]){ if(marked[b] == 1){ }else{ ///backk[x].push_back(a); low[x] = min(low[x],poz[a]); } }else{ ///normall[x].push_back(a); marked[b] = 1; poz[a] = poz[x] + 1; DFS2(a); low[x] = min(low[x],low[a]); if(low[a] >= poz[a]){ if(b > z2){ odp++; } } } } } } void F(int x, int y){ z1 = x; z2 = y; for(int i = 1; i <= n;i++){ odw[i] = odw2[i] = 0; poz[i] = 0; } for(int i = 1; i <= m;i++){ marked[i] = 0; } DFS(1); for(int i = 1; i <= n;i++){ if(odw[i] == 0){ odp += (m-y); return; } } poz[1] = 1; DFS2(1); } int main(void){ int a,b; scanf("%d %d",&n,&m); for(int i = 1; i <= m;i++){ scanf("%d %d",&a,&b); V[a].push_back({b,i}); V[b].push_back({a,i}); } for(int i = 1; i <= m;i++){ for(int j = i+1; j <= m;j++){ F(i,j); } } printf("%lld",odp); return 0; } |