#include<bits/stdc++.h> #define fi first #define se second using namespace std; pair<int,int> inp[500010]; vector<pair<int,int>> e[200010]; bool vis[200010]; int low[200010]; int g[200010]; void dfs(int x,int p) { vis[x]=true; low[x]=g[x]; for(auto v:e[x]) { if(v.se==p) continue; if(vis[v.fi]) low[x]=min(low[x],g[v.fi]); else { g[v.fi]=g[x]+1; dfs(v.fi,v.se); low[x]=min(low[x],low[v.fi]); } } return; } inline int solve(int n,int m) { for(int i=1;i<=n;i++) vis[i]=false; g[1]=1; dfs(1,0); int ans=0; for(int i=1;i<=n;i++) { //cerr<<i<<" "<<g[i]<<" "<<low[i]<<"\n"; if(!vis[i]) return m; if((low[i]==g[i])&&(i!=1)) ans++; } //cerr<<ans; return ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n,m,i,j,k; long long ans=0; cin>>n>>m; for(i=1;i<=m;i++) cin>>inp[i].fi>>inp[i].se; for(i=1;i<=m;i++) { for(j=i+1;j<=m;j++) { for(k=1;k<=n;k++) e[k].clear(); for(k=1;k<=m;k++) { if((k!=i)&&(k!=j)) { e[inp[k].fi].push_back({inp[k].se,k}); e[inp[k].se].push_back({inp[k].fi,k}); } } //cerr<<inp[i].fi<<","<<inp[i].se<<" "<<inp[j].fi<<","<<inp[j].se<<" "; ans+=solve(n,m-2); //cerr<<"\n"; } } cout<<(ans/3)<<"\n"; 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 | #include<bits/stdc++.h> #define fi first #define se second using namespace std; pair<int,int> inp[500010]; vector<pair<int,int>> e[200010]; bool vis[200010]; int low[200010]; int g[200010]; void dfs(int x,int p) { vis[x]=true; low[x]=g[x]; for(auto v:e[x]) { if(v.se==p) continue; if(vis[v.fi]) low[x]=min(low[x],g[v.fi]); else { g[v.fi]=g[x]+1; dfs(v.fi,v.se); low[x]=min(low[x],low[v.fi]); } } return; } inline int solve(int n,int m) { for(int i=1;i<=n;i++) vis[i]=false; g[1]=1; dfs(1,0); int ans=0; for(int i=1;i<=n;i++) { //cerr<<i<<" "<<g[i]<<" "<<low[i]<<"\n"; if(!vis[i]) return m; if((low[i]==g[i])&&(i!=1)) ans++; } //cerr<<ans; return ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n,m,i,j,k; long long ans=0; cin>>n>>m; for(i=1;i<=m;i++) cin>>inp[i].fi>>inp[i].se; for(i=1;i<=m;i++) { for(j=i+1;j<=m;j++) { for(k=1;k<=n;k++) e[k].clear(); for(k=1;k<=m;k++) { if((k!=i)&&(k!=j)) { e[inp[k].fi].push_back({inp[k].se,k}); e[inp[k].se].push_back({inp[k].fi,k}); } } //cerr<<inp[i].fi<<","<<inp[i].se<<" "<<inp[j].fi<<","<<inp[j].se<<" "; ans+=solve(n,m-2); //cerr<<"\n"; } } cout<<(ans/3)<<"\n"; return 0; } |