Submission #927256

# Submission time Handle Problem Language Result Execution time Memory
927256 2024-02-14T14:35:26 Z Ludissey Regions (IOI09_regions) C++14
0 / 100
115 ms 131072 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;
int N,R,Q; 
vector<vector<int>> child;
vector<int> r;
vector<vector<int>> cr;
vector<vector<int>> ans;

void dfs(int x){
    for (auto u : child[x])
    {
        dfs(u);
        for (int i = 0; i < R; i++)
        {
            cr[x][i]+=cr[u][i];
        }
        
    }
    for (int i = 0; i < R; i++) ans[r[x]][i]+=cr[x][i];
    cr[x][r[x]]++;
}

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
	cin >>N>>R>>Q;
    child.resize(N+1);
    cr.resize(N+1,vector<int>(R,0));
    ans.resize(R,vector<int>(R,0));
    r.resize(N+1);


    cin >> r[0];
    r[0]--;
    for (int i=1; i < N; i++)
    {
        int p; cin >> p >> r[i];
        r[i]--;
        child[p-1].push_back(i);
    }
    dfs(0);
    for (int i = 0; i < Q; i++)
    {
        int e1,e2; cin>>e1>>e2;
        e1--;
        e2--;
        int as=ans[r[e1]][r[e2]];
        cout << as << "\n";
    }
    
    return 0;
}
# Verdict Execution time Memory Grader output
1 Execution timed out 0 ms 596 KB Time limit exceeded (wall clock)
2 Execution timed out 0 ms 344 KB Time limit exceeded (wall clock)
3 Execution timed out 0 ms 344 KB Time limit exceeded (wall clock)
4 Execution timed out 0 ms 344 KB Time limit exceeded (wall clock)
5 Execution timed out 1 ms 600 KB Time limit exceeded (wall clock)
6 Execution timed out 2 ms 2392 KB Time limit exceeded (wall clock)
7 Execution timed out 2 ms 2392 KB Time limit exceeded (wall clock)
8 Execution timed out 3 ms 3928 KB Time limit exceeded (wall clock)
9 Execution timed out 10 ms 13400 KB Time limit exceeded (wall clock)
10 Execution timed out 31 ms 35664 KB Time limit exceeded (wall clock)
11 Execution timed out 28 ms 34160 KB Time limit exceeded (wall clock)
12 Execution timed out 60 ms 74540 KB Time limit exceeded (wall clock)
13 Execution timed out 54 ms 67228 KB Time limit exceeded (wall clock)
14 Execution timed out 46 ms 50488 KB Time limit exceeded (wall clock)
15 Execution timed out 64 ms 81884 KB Time limit exceeded (wall clock)
# Verdict Execution time Memory Grader output
1 Execution timed out 115 ms 126332 KB Time limit exceeded (wall clock)
2 Runtime error 50 ms 131072 KB Execution killed with signal 9
3 Runtime error 49 ms 131072 KB Execution killed with signal 9
4 Runtime error 50 ms 131072 KB Execution killed with signal 9
5 Runtime error 72 ms 131072 KB Execution killed with signal 9
6 Runtime error 64 ms 131072 KB Execution killed with signal 9
7 Runtime error 50 ms 131072 KB Execution killed with signal 9
8 Runtime error 49 ms 131072 KB Execution killed with signal 9
9 Runtime error 49 ms 131072 KB Execution killed with signal 9
10 Runtime error 46 ms 131072 KB Execution killed with signal 9
11 Runtime error 46 ms 131072 KB Execution killed with signal 9
12 Runtime error 49 ms 131072 KB Execution killed with signal 9
13 Runtime error 56 ms 131072 KB Execution killed with signal 9
14 Runtime error 46 ms 131072 KB Execution killed with signal 9
15 Runtime error 47 ms 131072 KB Execution killed with signal 9
16 Runtime error 57 ms 131072 KB Execution killed with signal 9
17 Runtime error 46 ms 131072 KB Execution killed with signal 9