Submission #248707

# Submission time Handle Problem Language Result Execution time Memory
248707 2020-07-13T08:19:12 Z Lawliet Synchronization (JOI13_synchronization) C++17
0 / 100
120 ms 18552 KB
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 100010;
const int INF = 1000000010;

int n, m, q;

int mnTime[MAXN], mxTime[MAXN];

bool act[MAXN];

vector<int> adj[MAXN];
vector<int> indEdge[MAXN];

int DFS(int cur, int p, int t)
{
	int ans = 1;

	for(int i = 0 ; i < (int)adj[cur].size() ; i++)
	{
		int viz = adj[cur][i];
		int ind = indEdge[cur][i];

		if( viz == p ) continue;
		if( t < mnTime[ind] ) continue;

		ans += DFS( viz , cur , min( t , mxTime[ind] ) );
	}

	return ans;
}

int main()
{
	scanf("%d %d %d",&n,&m,&q);

	for(int i = 1 ; i < n ; i++)
	{
		int U, V;
		scanf("%d %d",&U,&V);

		adj[U].push_back( V );
		adj[V].push_back( U );

		indEdge[U].push_back( i );
		indEdge[V].push_back( i );

		mnTime[i] = INF; mxTime[i] = -INF;
	}

	for(int i = 1 ; i <= m ; i++)
	{
		int ind;
		scanf("%d",&ind);

		if( !act[ind] ) mnTime[ind] = min( mnTime[ind] , i );
		else mxTime[ind] = max( mxTime[ind] , i - 1 );

		act[ind] = !act[ind];
	}

	for(int i = 1 ; i < n ; i++)
		if( mnTime[i] != INF && mnTime[i] > mxTime[i] ) mxTime[i] = INF;

	for(int i = 1 ; i <= q ; i++)
	{
		int root;
		scanf("%d",&root);

		printf("%d\n",DFS( root , root , INF ));
	}
}

Compilation message

synchronization.cpp: In function 'int main()':
synchronization.cpp:37:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d %d",&n,&m,&q);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~
synchronization.cpp:42:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d",&U,&V);
   ~~~~~^~~~~~~~~~~~~~~
synchronization.cpp:56:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&ind);
   ~~~~~^~~~~~~~~~~
synchronization.cpp:70:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&root);
   ~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4992 KB Output is correct
2 Correct 3 ms 4992 KB Output is correct
3 Incorrect 3 ms 4992 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 78 ms 18552 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 4992 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 120 ms 15352 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4992 KB Output is correct
2 Incorrect 3 ms 4992 KB Output isn't correct
3 Halted 0 ms 0 KB -