Submission #163199

# Submission time Handle Problem Language Result Execution time Memory
163199 2019-11-11T18:03:13 Z TadijaSebez 전압 (JOI14_voltage) C++11
100 / 100
156 ms 14072 KB
#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

voltage.cpp: In function 'int main()':
voltage.cpp:46:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%i %i",&n,&m);
  ~~~~~^~~~~~~~~~~~~~~
voltage.cpp:47:59: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=1,u,v;i<=m;i++) scanf("%i %i",&u,&v),E[u].pb(v),E[v].pb(u);
                            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 2936 KB Output is correct
2 Correct 5 ms 2680 KB Output is correct
3 Correct 5 ms 2680 KB Output is correct
4 Correct 5 ms 2680 KB Output is correct
5 Correct 5 ms 2808 KB Output is correct
6 Correct 5 ms 2808 KB Output is correct
7 Correct 5 ms 2808 KB Output is correct
8 Correct 5 ms 2836 KB Output is correct
9 Correct 5 ms 2808 KB Output is correct
10 Correct 5 ms 2808 KB Output is correct
11 Correct 6 ms 2808 KB Output is correct
12 Correct 5 ms 2808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 41 ms 7932 KB Output is correct
2 Correct 80 ms 11000 KB Output is correct
3 Correct 50 ms 7920 KB Output is correct
4 Correct 95 ms 11896 KB Output is correct
5 Correct 11 ms 3448 KB Output is correct
6 Correct 83 ms 9904 KB Output is correct
7 Correct 77 ms 12908 KB Output is correct
8 Correct 109 ms 13020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 7664 KB Output is correct
2 Correct 49 ms 12920 KB Output is correct
3 Correct 49 ms 12940 KB Output is correct
4 Correct 4 ms 2680 KB Output is correct
5 Correct 57 ms 9468 KB Output is correct
6 Correct 69 ms 8312 KB Output is correct
7 Correct 113 ms 10332 KB Output is correct
8 Correct 104 ms 11416 KB Output is correct
9 Correct 79 ms 11076 KB Output is correct
10 Correct 71 ms 10104 KB Output is correct
11 Correct 68 ms 8316 KB Output is correct
12 Correct 77 ms 9464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 59 ms 9068 KB Output is correct
2 Correct 78 ms 14072 KB Output is correct
3 Correct 5 ms 2808 KB Output is correct
4 Correct 91 ms 11000 KB Output is correct
5 Correct 92 ms 11772 KB Output is correct
6 Correct 86 ms 10844 KB Output is correct
7 Correct 136 ms 12536 KB Output is correct
8 Correct 134 ms 13048 KB Output is correct
9 Correct 147 ms 11604 KB Output is correct
10 Correct 148 ms 13432 KB Output is correct
11 Correct 137 ms 11768 KB Output is correct
12 Correct 155 ms 13388 KB Output is correct
13 Correct 134 ms 11568 KB Output is correct
14 Correct 156 ms 14016 KB Output is correct
15 Correct 145 ms 13452 KB Output is correct
16 Correct 142 ms 13044 KB Output is correct
17 Correct 117 ms 11452 KB Output is correct
18 Correct 108 ms 11636 KB Output is correct