Submission #34034

# Submission time Handle Problem Language Result Execution time Memory
34034 2017-11-06T14:00:08 Z ToMoClone 스파이 (JOI13_spy) C++14
100 / 100
233 ms 17952 KB
/*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

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 time Memory Grader output
1 Correct 0 ms 17820 KB Output is correct
2 Correct 0 ms 17820 KB Output is correct
3 Correct 0 ms 17820 KB Output is correct
4 Correct 0 ms 17820 KB Output is correct
5 Correct 0 ms 17820 KB Output is correct
6 Correct 0 ms 17820 KB Output is correct
7 Correct 0 ms 17820 KB Output is correct
8 Correct 0 ms 17820 KB Output is correct
9 Correct 0 ms 17820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 17952 KB Output is correct
2 Correct 39 ms 17952 KB Output is correct
3 Correct 13 ms 17820 KB Output is correct
4 Correct 16 ms 17820 KB Output is correct
5 Correct 9 ms 17820 KB Output is correct
6 Correct 13 ms 17820 KB Output is correct
7 Correct 13 ms 17952 KB Output is correct
8 Correct 6 ms 17820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 213 ms 17952 KB Output is correct
2 Correct 136 ms 17952 KB Output is correct
3 Correct 136 ms 17820 KB Output is correct
4 Correct 139 ms 17820 KB Output is correct
5 Correct 159 ms 17820 KB Output is correct
6 Correct 113 ms 17820 KB Output is correct
7 Correct 196 ms 17952 KB Output is correct
8 Correct 233 ms 17820 KB Output is correct