Submission #418201

#TimeUsernameProblemLanguageResultExecution timeMemory
418201victoriadRegions (IOI09_regions)C++14
12 / 100
8090 ms26888 KiB
#include <cmath> #include <cstdio> #include <vector> #include <iostream> #include <algorithm> #include <utility> #include <queue> #include <map> #include <iomanip> using namespace std; vector<int>region; int total; void dfs(int nodo,vector<vector<int> >&g,vector<bool>&vi,int b,int x,int a){ vi[nodo]=true; if(region[nodo]==b)total+=x; if(region[nodo]==a)x++; for(int c:g[nodo]){ if(!vi[c]){ dfs(c,g,vi,b,x,a); } } } 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--; total=0; vector<bool>vi(N,false); dfs(0,g,vi,b,0,a); cout<<total<<"\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...