#include <bits/stdc++.h>
using namespace std;
const int mx=5e5+2;
const int maxn=2e5+2;
int n,m,ileodw,wyn;
int a[mx],b[mx];
vector<int>g[maxn];
int odw[maxn];
void dfs(int w){
++ileodw;
odw[w]=1;
for(int i=0;i<g[w].size();++i){
int x=g[w][i];
if(!odw[x]){
dfs(x);
}
}
}
int main(){
ios::sync_with_stdio(false);
cin>>n>>m;
for(int i=0;i<m;++i){
cin>>a[i]>>b[i];
}
for(int i=0;i<m;++i){
for(int j=i+1;j<m;++j){
for(int k=j+1;k<m;++k){
for(int l=1;l<=n;++l){
g[l].clear();
odw[l]=0;
}
for(int l=0;l<m;++l){
if(l==i||l==j||l==k)continue;
g[a[l]].push_back(b[l]);
g[b[l]].push_back(a[l]);
}
ileodw=0;
dfs(1);
if(ileodw!=n)++wyn;
}
}
}
cout<<wyn;
}
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 | #include <bits/stdc++.h> using namespace std; const int mx=5e5+2; const int maxn=2e5+2; int n,m,ileodw,wyn; int a[mx],b[mx]; vector<int>g[maxn]; int odw[maxn]; void dfs(int w){ ++ileodw; odw[w]=1; for(int i=0;i<g[w].size();++i){ int x=g[w][i]; if(!odw[x]){ dfs(x); } } } int main(){ ios::sync_with_stdio(false); cin>>n>>m; for(int i=0;i<m;++i){ cin>>a[i]>>b[i]; } for(int i=0;i<m;++i){ for(int j=i+1;j<m;++j){ for(int k=j+1;k<m;++k){ for(int l=1;l<=n;++l){ g[l].clear(); odw[l]=0; } for(int l=0;l<m;++l){ if(l==i||l==j||l==k)continue; g[a[l]].push_back(b[l]); g[b[l]].push_back(a[l]); } ileodw=0; dfs(1); if(ileodw!=n)++wyn; } } } cout<<wyn; } |
English