Submission #825391

# Submission time Handle Problem Language Result Execution time Memory
825391 2023-08-14T19:22:45 Z serifefedartar Regions (IOI09_regions) C++17
5 / 100
67 ms 15228 KB
#include <bits/stdc++.h>
using namespace std;
 
#define fast ios::sync_with_stdio(0);cin.tie(0);
typedef long long ll;
#define f first
#define s second
#define MOD 1000000007
#define LOGN 20
#define MAXN 200005
#define pb push_back

vector<vector<int>> graph;
int ans[505][505], cnt[505][505];
int region[MAXN];
void dfs(int node, int parent) {
	for (int i = 0; i <= 500; i++) {
		cnt[node][i] = cnt[parent][i];
		ans[i][region[node]] += cnt[node][i];
	}
	cnt[node][region[node]]++;

	for (auto u : graph[node]) {
		dfs(u, node);
	}
}

int main() {
	fast
	memset(ans, 0, sizeof(ans));
	memset(cnt, 0, sizeof(cnt));
	int N, R, Q, S, r1, r2;
    cin >> N >> R >> Q >> region[1];

    graph = vector<vector<int>>(N+1, vector<int>());
    for (int i = 2; i <= N; i++) {
    	cin >> S >> region[i]; 
    	graph[S].pb(i);
    }

    if (R <= 500) {
    	dfs(1, 1);
    	while (Q--) {
    		cin >> r1 >> r2;
    		cout << ans[r1][r2] << endl;
    	}
    } else {
		while (Q--) {
			int x, y;
			cin >> x >> y;
			cout << x << " " << y << endl;
		}
	}
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2256 KB Output is correct
2 Correct 1 ms 2256 KB Output is correct
3 Correct 2 ms 2256 KB Output is correct
4 Correct 5 ms 2256 KB Output is correct
5 Correct 7 ms 2256 KB Output is correct
6 Incorrect 13 ms 2384 KB Output isn't correct
7 Runtime error 4 ms 4652 KB Execution killed with signal 11
8 Runtime error 4 ms 4688 KB Execution killed with signal 11
9 Runtime error 5 ms 5072 KB Execution killed with signal 11
10 Runtime error 5 ms 5592 KB Execution killed with signal 11
11 Runtime error 6 ms 6224 KB Execution killed with signal 11
12 Runtime error 8 ms 6864 KB Execution killed with signal 11
13 Runtime error 8 ms 6644 KB Execution killed with signal 11
14 Runtime error 8 ms 7804 KB Execution killed with signal 11
15 Runtime error 11 ms 9324 KB Execution killed with signal 11
# Verdict Execution time Memory Grader output
1 Runtime error 17 ms 13180 KB Execution killed with signal 11
2 Runtime error 18 ms 12104 KB Execution killed with signal 11
3 Runtime error 21 ms 15228 KB Execution killed with signal 11
4 Runtime error 24 ms 3916 KB Execution killed with signal 13
5 Execution timed out 29 ms 4532 KB Time limit exceeded (wall clock)
6 Execution timed out 30 ms 5092 KB Time limit exceeded (wall clock)
7 Execution timed out 25 ms 6036 KB Time limit exceeded (wall clock)
8 Execution timed out 39 ms 8144 KB Time limit exceeded (wall clock)
9 Execution timed out 43 ms 10736 KB Time limit exceeded (wall clock)
10 Execution timed out 52 ms 12304 KB Time limit exceeded (wall clock)
11 Execution timed out 67 ms 11432 KB Time limit exceeded (wall clock)
12 Execution timed out 65 ms 13376 KB Time limit exceeded (wall clock)
13 Execution timed out 54 ms 12820 KB Time limit exceeded (wall clock)
14 Execution timed out 45 ms 12908 KB Time limit exceeded (wall clock)
15 Execution timed out 51 ms 14024 KB Time limit exceeded (wall clock)
16 Execution timed out 56 ms 14004 KB Time limit exceeded (wall clock)
17 Execution timed out 45 ms 14064 KB Time limit exceeded (wall clock)