Submission #34034

#TimeUsernameProblemLanguageResultExecution timeMemory
34034ToMoClone스파이 (JOI13_spy)C++14
100 / 100
233 ms17952 KiB
/*input
3 4
0 2
1 0
2 2
1 1
2 1
2 3
3 2
*/
#include <bits/stdc++.h>
using namespace std;

const int N = 2007;

int startI[N], finishI[N], par[N], ans[N][N], n, m, rootI, cnt;
vector<int> childI[N];

void dfs(int u){
	startI[u] = ++cnt;
	for(auto v:childI[u]) dfs(v);
	finishI[u] = cnt + 1;
}

int main(){
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; ++i){
		int a, b; scanf("%d%d", &a, &b);
		childI[b].push_back(i);
		if(b == 0) rootI = i;
		par[i] = a;
	}

	dfs(rootI);

	for(int i = 1; i <= m; ++i){
		int a, b; scanf("%d%d", &a, &b);
		++ans[a][startI[b]];
		--ans[a][finishI[b]];
	}

	for(int i = 1; i <= n; ++i)
		for(int j = 1; j <= n; ++j)
			ans[i][j] += ans[i][j - 1];

	for(int i = 1; i <= n; ++i){
		int k = i, res = 0;
		while(k != 0) res += ans[k][startI[i]], k = par[k];
		printf("%d\n", res);
	}
}

Compilation message (stderr)

spy.cpp: In function 'int main()':
spy.cpp:26:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &m);
                       ^
spy.cpp:28:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int a, b; scanf("%d%d", &a, &b);
                                  ^
spy.cpp:37:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int a, b; scanf("%d%d", &a, &b);
                                  ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...