This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<stdio.h>
#include<vector>
using namespace std;
vector<int>con[100010];
int cnt,n,m,ch[100010],lev[100010],arr2[100010],arr[100010],dap,ch2[100010];
void dfs(int x,int bef)
{
int i,sw=0;
ch[x]=1;
for(i=0;i<con[x].size();i++){
if(con[x][i]==bef && sw==0){sw=1; continue;}
if(ch[con[x][i]]){
if(lev[x]<lev[con[x][i]]) continue;
if((lev[x]-lev[con[x][i]])%2==1) arr[x]++, arr[con[x][i]]--;
else arr2[x]++, arr2[con[x][i]]--, cnt++;
continue;
}
lev[con[x][i]]=lev[x]+1;
dfs(con[x][i],x);
}
}
void dfs2(int x,int bef)
{
int i,sw=0;
ch2[x]=1;
for(i=0;i<con[x].size();i++){
if(con[x][i]==bef && sw==0){sw=1; continue;}
if(ch2[con[x][i]]) continue;
dfs2(con[x][i],x);
arr[x]+=arr[con[x][i]];
arr2[x]+=arr2[con[x][i]];
}
}
int main()
{
int i,x,y;
scanf("%d %d",&n,&m);
for(i=1;i<=m;i++){
scanf("%d %d",&x,&y);
con[x].push_back(y); con[y].push_back(x);
}
for(i=1;i<=n;i++)
{
if(ch[i]) continue;
dfs(i,0);
dfs2(i,0);
ch[i]=2;
}
for(i=1;i<=n;i++)
{
if(arr2[i]==cnt && arr[i]==0 && ch[i]==1) dap++;
}
if(cnt==1) dap++;
printf("%d",dap);
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |