Submission #394129

# Submission time Handle Problem Language Result Execution time Memory
394129 2021-04-25T17:49:26 Z victoriad Regions (IOI09_regions) C++14
12 / 100
8000 ms 26844 KB
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <utility>
#include <queue>
#include <map>
#include <iomanip>
using namespace std;
 vector<int>region;
 void dfs(vector<vector<int> >&g,int nodo,int bus,vector<bool>&v,int & r){
   v[nodo]=true;
   if(region[nodo]==bus)r++;
   for(int c:g[nodo]){
     if(!v[c]){
       dfs(g,c,bus,v,r);
     }
   }
 }

int main(){
  int N,R,Q;
  cin>>N>>R>>Q;
  vector<vector<int> >g(N);
  g.clear();
  region.resize(N);
  int a,b;
  cin>>a;
  a--;
  region[0]=a;

  for(int i=1;i<N;i++){
    cin>>a>>b;
    a--;
    b--;
    region[i]=b;
    g[a].push_back(i);
  }
   
  for(int i=0;i<Q;i++){
    cin>>a>>b;
    a--;
    b--;
    int con=0;
    for(int k=0;k<N;k++){
      if(region[k]==a){
      vector<bool>v(N,false);
      dfs(g,k,b,v,con);
      }
    }
    cout<<con<<"\n";
    }
    
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 200 KB Output is correct
2 Correct 1 ms 200 KB Output is correct
3 Correct 2 ms 200 KB Output is correct
4 Correct 5 ms 200 KB Output is correct
5 Correct 17 ms 200 KB Output is correct
6 Correct 48 ms 328 KB Output is correct
7 Correct 73 ms 328 KB Output is correct
8 Correct 131 ms 328 KB Output is correct
9 Correct 2353 ms 968 KB Output is correct
10 Correct 686 ms 840 KB Output is correct
11 Correct 4392 ms 1096 KB Output is correct
12 Execution timed out 8016 ms 1776 KB Time limit exceeded
13 Correct 1341 ms 1356 KB Output is correct
14 Execution timed out 8031 ms 1944 KB Time limit exceeded
15 Execution timed out 8070 ms 5824 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Execution timed out 8085 ms 5660 KB Time limit exceeded
2 Execution timed out 8048 ms 4160 KB Time limit exceeded
3 Execution timed out 8086 ms 8264 KB Time limit exceeded
4 Execution timed out 8048 ms 1992 KB Time limit exceeded
5 Execution timed out 8067 ms 4440 KB Time limit exceeded
6 Execution timed out 8099 ms 3392 KB Time limit exceeded
7 Execution timed out 8013 ms 4288 KB Time limit exceeded
8 Execution timed out 8007 ms 11480 KB Time limit exceeded
9 Execution timed out 8013 ms 10312 KB Time limit exceeded
10 Execution timed out 8028 ms 17352 KB Time limit exceeded
11 Execution timed out 8022 ms 9728 KB Time limit exceeded
12 Execution timed out 8045 ms 11620 KB Time limit exceeded
13 Execution timed out 8045 ms 12296 KB Time limit exceeded
14 Execution timed out 8018 ms 11652 KB Time limit exceeded
15 Execution timed out 8044 ms 17416 KB Time limit exceeded
16 Execution timed out 8034 ms 26844 KB Time limit exceeded
17 Execution timed out 8029 ms 24964 KB Time limit exceeded