Submission #345117

#TimeUsernameProblemLanguageResultExecution timeMemory
345117daniel920712Tropical Garden (IOI11_garden)C++14
0 / 100
15 ms5356 KiB
#include "garden.h" #include "gardenlib.h" #include "gardenlib.h" #include <vector> #include <utility> #include <algorithm> using namespace std; int con[100005]; vector < pair < int , int > > Next[100005]; pair < int , int > tra[5][35][100005]; int Father[100005]; bool F(int fa,int here,int how,int where,int deg) { if(deg==how) return where==here; if(con[here]==1||fa!=Next[here][0].second) return F(here,Next[here][0].second,how,where,deg+1); else return F(here,Next[here][1].second,how,where,deg+1); } void count_routes(int N, int M, int P, int R[][2], int Q, int G[]) { int i,now=0,j,k; for(i=0;i<M;i++) { Next[R[i][0]].push_back(make_pair(i,R[i][1])); Next[R[i][1]].push_back(make_pair(i,R[i][0])); con[R[i][0]]++; con[R[i][1]]++; } for(i=0;i<N;i++) { sort(Next[i].begin(),Next[i].end()); if(con[i]==1) Father[i]=-1; else Father[i]=Next[i][0].first; } for(i=0;i<N;i++) { tra[0][0][i]=make_pair(i,Next[i][0].second); if(Father[i]!=-1) tra[1][0][i]=make_pair(i,Next[i][1].second); } for(i=1;i<=30;i++) { for(j=0;j<N;j++) { if(tra[0][j-1][i].first==Father[tra[0][j-1][i].first]) tra[0][j][i]=tra[1][j-1][tra[0][j-1][i].second]; else tra[0][j][i]=tra[0][j-1][tra[0][j-1][i].second]; if(tra[1][j-1][i].first==Father[tra[1][j-1][i].first]) tra[1][j][i]=tra[1][j-1][tra[1][j-1][i].second]; else tra[1][j][i]=tra[0][j-1][tra[1][j-1][i].second]; } } for(i=0;i<Q;i++) { for(j=0;j<N;j++) { pair < int , int > tt=make_pair(-1,j); for(k=0;k<=30;k++) { if(G[i]&(1<<k)) { if(tt.first==Father[tt.second]) tt=tra[1][j][tt.second]; else tt=tra[0][j][tt.second]; } } } answer(now); } } /* 6 6 0 1 2 0 1 0 3 3 4 4 5 1 5 1 3 2 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...