제출 #321323

#제출 시각아이디문제언어결과실행 시간메모리
321323ronnithRegions (IOI09_regions)C++14
30 / 100
1740 ms26980 KiB
#include <bits/stdc++.h>

#define FOR(i,a,b) for(int i = a;i < b;i ++)
#define trav(e,x) for(auto e:x)
#define maxn 200000
#define maxr 500

using namespace std;

int N, R, Q, region[maxn], ans[maxr][maxr];
vector<int> adj[maxn];

void dfs(int x,int pr,int crr,int val)
{
	if(region[x] == crr)val ++;
	ans[crr][region[x]] += val;
	trav(e,adj[x])
	{
		if(e != pr)
		{
			dfs(e,x,crr,val);
		}
	}
}

void preProccess()
{
	FOR(i,0,R)
	{
		dfs(0,-1,i,0);
	}
}

int main()
{
	scanf("%d%d%d",&N,&R,&Q);
	
	int x,y;
	scanf("%d",&x);
	region[0] = x - 1;
	FOR(i,0,N - 1)
	{
		scanf("%d%d",&x,&y);
		x --;y --;
		adj[i + 1].push_back(x);
		adj[x].push_back(i + 1);
		region[i + 1] = y;
	}
	FOR(i,0,R)
	{
		fill(ans[i],ans[i] + R,0);
	}

	preProccess();

	FOR(i,0,Q)
	{
		scanf("%d%d",&x,&y);
		x --;y --;
		printf("%d\n", ans[x][y]);
		fflush(stdout);
	}

	return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

regions.cpp: In function 'int main()':
regions.cpp:36:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   36 |  scanf("%d%d%d",&N,&R,&Q);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~
regions.cpp:39:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   39 |  scanf("%d",&x);
      |  ~~~~~^~~~~~~~~
regions.cpp:43:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   43 |   scanf("%d%d",&x,&y);
      |   ~~~~~^~~~~~~~~~~~~~
regions.cpp:58:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   58 |   scanf("%d%d",&x,&y);
      |   ~~~~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...