제출 #417934

#제출 시각아이디문제언어결과실행 시간메모리
417934victoriadRegions (IOI09_regions)C++14
4 / 100
1399 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<N;i++){ int j=region[i]; if(bus[j][j]==0){ vector<bool>vi(N,false); dfs(i,g,vi,bus[j],0,j); } } for(int i=0;i<Q;i++){ cin>>a>>b; a--; b--; cout<<bus[a][b]<<"\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...