Submission #638134

# Submission time Handle Problem Language Result Execution time Memory
638134 2022-09-04T17:44:02 Z Iwanttobreakfree Regions (IOI09_regions) C++17
13 / 100
8000 ms 20932 KB
#include <iostream>
#include <vector>
using namespace std;
int ans;
void dfs(int a,vector<vector<int>>& g,vector<int>& reg,int target){
    if(reg[a]==target)ans++;
    for(int x:g[a]){
        dfs(x,g,reg,target);
    }
}
int main(){
    int n,r,q,x,y;
    cin>>n>>r>>q;
    vector<int> reg(n);
    vector<vector<int>> g(n,vector<int>());
    cin>>reg[0];
    for(int i=1;i<n;i++){
        cin>>x>>reg[i];
        x--;
        g[x].push_back(i);
    }
    while(q--){
        cin>>x>>y;
        ans=0;
        for(int i=0;i<n;i++)if(reg[i]==x)dfs(i,g,reg,y);
        cout<<ans<<'\n';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 3 ms 208 KB Output is correct
4 Correct 4 ms 208 KB Output is correct
5 Correct 11 ms 208 KB Output is correct
6 Correct 38 ms 380 KB Output is correct
7 Correct 48 ms 336 KB Output is correct
8 Correct 93 ms 424 KB Output is correct
9 Correct 1278 ms 720 KB Output is correct
10 Correct 495 ms 848 KB Output is correct
11 Correct 3178 ms 1104 KB Output is correct
12 Execution timed out 8080 ms 1616 KB Time limit exceeded
13 Correct 976 ms 1240 KB Output is correct
14 Correct 7977 ms 1872 KB Output is correct
15 Execution timed out 8038 ms 4504 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Execution timed out 8025 ms 5280 KB Time limit exceeded
2 Execution timed out 8096 ms 4124 KB Time limit exceeded
3 Execution timed out 8029 ms 7248 KB Time limit exceeded
4 Execution timed out 8082 ms 1872 KB Time limit exceeded
5 Execution timed out 8063 ms 3660 KB Time limit exceeded
6 Execution timed out 8083 ms 3196 KB Time limit exceeded
7 Execution timed out 8093 ms 4172 KB Time limit exceeded
8 Execution timed out 8087 ms 9456 KB Time limit exceeded
9 Execution timed out 8022 ms 9592 KB Time limit exceeded
10 Execution timed out 8021 ms 14508 KB Time limit exceeded
11 Execution timed out 8074 ms 9552 KB Time limit exceeded
12 Execution timed out 8022 ms 11404 KB Time limit exceeded
13 Execution timed out 8098 ms 11760 KB Time limit exceeded
14 Execution timed out 8010 ms 11280 KB Time limit exceeded
15 Execution timed out 8005 ms 15448 KB Time limit exceeded
16 Execution timed out 8095 ms 20932 KB Time limit exceeded
17 Execution timed out 8098 ms 19752 KB Time limit exceeded