Submission #717774

#TimeUsernameProblemLanguageResultExecution timeMemory
717774TheSahibTropical Garden (IOI11_garden)C++17
49 / 100
5072 ms6228 KiB
#include "garden.h" #include "gardenlib.h" #include <bits/stdc++.h> #define ll long long #define pii pair<int, int> using namespace std; bool comp(pii a, pii b){ return a.second > b.second; } const int MAX = 2e5 + 5; vector<pii> g[MAX]; int last[MAX]; int t = 1; int f = 0; bool dfs(int node, int left){ if(left == 0){ return node == f; } if(g[node].size() == 1 || (last[g[node][0].second] <= last[g[node][1].second])){ for(pii &a:g[g[node][0].first]){ last[a.second] = 0; } last[g[node][0].second] = ++t; return dfs(g[node][0].first, left - 1); } else{ for(pii &a:g[g[node][1].first]){ last[a.second] = 0; } last[g[node][1].second] = ++t; return dfs(g[node][1].first, left - 1); } } void count_routes(int N, int M, int P, int R[][2], int Q, int G[]) { f = P; for (int i = 0; i < M; i++) { g[R[i][0]].push_back({R[i][1], M - i - 1}); g[R[i][1]].push_back({R[i][0], M - i - 1}); } for (int i = 0; i < N; i++) { sort(g[i].begin(), g[i].end(), comp); } for (int j = 0; j < Q; j++) { int ans = 0; for (int i = 0; i < N; i++) { t = 0; fill(last, last + M, 0); ans += dfs(i, G[j]); } answer(ans); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...