Submission #416085

#TimeUsernameProblemLanguageResultExecution timeMemory
416085dreezyTropical Garden (IOI11_garden)C++17
49 / 100
5054 ms716 KiB
#include <bits/stdc++.h> #include "garden.h" #include "gardenlib.h" using namespace std; /*****************************************/ //just have to implement #define pi pair<int,int> #define pb push_back #define ll long long #define f first #define s second const int maxn = 2e3 +5; //int level[maxn]; int graph[maxn][2]; bool follow_path(int n,int p, int k){ //cout << n <<": "; int prev = -1; for(int i =0; i<k; i++){ if(graph[n][0]== prev) { prev = n; n = graph[n][1]; } else{ prev = n; n = graph[n][0]; } } //cout << n <<", "<< p<<", "<<k<<endl; if(n == p) return 1; return 0; } void count_routes(int N, int M, int P, int R[][2], int Q, int G[]) { memset(graph, -1, sizeof(graph)); for(int i =0; i<M; i++){ int a = R[i][0]; int b = R[i][1]; if(graph[a][0] == -1){ graph[a][0] = b; graph[a][1] = b; } else if(graph[a][0] == graph[a][1]){ graph[a][1] = b; } if(graph[b][0] == -1){ graph[b][0] = a; graph[b][1] = a; } else if(graph[b][0] == graph[b][1]){ graph[b][1] = a; } } /* for(int i =0; i< N; i++){ cout << i <<" -> "<<graph[i ][0]<<"\n"; cout << i <<"' -> "<<graph[i ][1]<<"\n"; }*/ for(int i =0; i<Q; i++){ ll ans = 0; for(int j =0; j<N; j++){ ans+=follow_path(j,P, G[i]); } answer(ans); } } /******************************************/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...