Submission #418214

#TimeUsernameProblemLanguageResultExecution timeMemory
418214victoriadRegions (IOI09_regions)C++14
15 / 100
5113 ms131076 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; void dfs(int nodo,vector<vector<int> >&g,vector<bool>&vi,vector<int>&b,int x,int a){ vi[nodo]=true; b[region[nodo]]+=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); } vector<vector<int> >bus(R); vector<int>vacio(R,0); for(int i=0;i<R;i++)bus[i]=vacio; for(int i=0;i<Q;i++){ cin>>a>>b; a--; b--; if(bus[a][b]==0){ vector<bool>vi(N,false); dfs(0,g,vi,bus[a],0,a); } cout<<bus[a][b]<<"\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...