# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
163199 | TadijaSebez | 전압 (JOI14_voltage) | C++11 | 156 ms | 14072 KiB |
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 <bits/stdc++.h>
using namespace std;
#define pb push_back
const int N=100050;
vector<int> E[N];
int even[N],odd[N],dep[N],all_odd;
bool was[N];
void DFS(int u)
{
was[u]=1;
int p=1;
for(int v:E[u])
{
if(!was[v])
{
dep[v]=dep[u]+1;
DFS(v);
}
else if(dep[u]>dep[v])
{
if(dep[u]==dep[v]+1 && p) p--;
else
{
if((dep[u]-dep[v])%2==0) odd[u]++,odd[v]--,all_odd++;
else even[u]++,even[v]--;
}
}
}
}
void SubTree(int u)
{
was[u]=1;
for(int v:E[u])
{
if(!was[v])
{
SubTree(v);
odd[u]+=odd[v];
even[u]+=even[v];
}
}
}
int main()
{
int n,m;
scanf("%i %i",&n,&m);
for(int i=1,u,v;i<=m;i++) scanf("%i %i",&u,&v),E[u].pb(v),E[v].pb(u);
for(int i=1;i<=n;i++) if(!was[i]) DFS(i);
for(int i=1;i<=n;i++) was[i]=0;
for(int i=1;i<=n;i++) if(!was[i]) SubTree(i);
int ans=0;
for(int i=1;i<=n;i++) if(dep[i]!=0 && odd[i]==all_odd && even[i]==0) ans++;
if(all_odd==1) ans++;
printf("%i\n",ans);
return 0;
}
Compilation message (stderr)
# | 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... |