Submission #825378

# Submission time Handle Problem Language Result Execution time Memory
825378 2023-08-14T19:04:46 Z serifefedartar Regions (IOI09_regions) C++17
5 / 100
69 ms 15164 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
    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 1232 KB Output is correct
2 Correct 1 ms 1360 KB Output is correct
3 Correct 2 ms 1360 KB Output is correct
4 Correct 5 ms 1616 KB Output is correct
5 Correct 8 ms 2256 KB Output is correct
6 Incorrect 19 ms 2384 KB Output isn't correct
7 Runtime error 3 ms 4376 KB Execution killed with signal 11
8 Runtime error 4 ms 4560 KB Execution killed with signal 11
9 Runtime error 4 ms 5048 KB Execution killed with signal 11
10 Runtime error 5 ms 4560 KB Execution killed with signal 11
11 Runtime error 6 ms 6224 KB Execution killed with signal 11
12 Runtime error 8 ms 6908 KB Execution killed with signal 11
13 Runtime error 6 ms 4816 KB Execution killed with signal 11
14 Runtime error 8 ms 7344 KB Execution killed with signal 11
15 Runtime error 11 ms 9296 KB Execution killed with signal 11
# Verdict Execution time Memory Grader output
1 Runtime error 17 ms 12908 KB Execution killed with signal 11
2 Runtime error 18 ms 12088 KB Execution killed with signal 11
3 Runtime error 21 ms 15164 KB Execution killed with signal 11
4 Runtime error 26 ms 1872 KB Execution killed with signal 13
5 Execution timed out 28 ms 2512 KB Time limit exceeded (wall clock)
6 Execution timed out 28 ms 3132 KB Time limit exceeded (wall clock)
7 Execution timed out 28 ms 4048 KB Time limit exceeded (wall clock)
8 Execution timed out 36 ms 6216 KB Time limit exceeded (wall clock)
9 Execution timed out 35 ms 8808 KB Time limit exceeded (wall clock)
10 Execution timed out 59 ms 10264 KB Time limit exceeded (wall clock)
11 Execution timed out 45 ms 9416 KB Time limit exceeded (wall clock)
12 Execution timed out 50 ms 11376 KB Time limit exceeded (wall clock)
13 Execution timed out 63 ms 10848 KB Time limit exceeded (wall clock)
14 Execution timed out 46 ms 10988 KB Time limit exceeded (wall clock)
15 Execution timed out 53 ms 12056 KB Time limit exceeded (wall clock)
16 Execution timed out 57 ms 12036 KB Time limit exceeded (wall clock)
17 Execution timed out 69 ms 12040 KB Time limit exceeded (wall clock)