# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
28804 | 2017-07-17T08:37:12 Z | kavun | Tropical Garden (IOI11_garden) | C++14 | 0 ms | 0 KB |
#include "garden.h" #include "gardenlib.h" #include <bits/stdc++.h> using namespace std; vector <pair<int,int> > adj[2000]; int dfs(int v, int d, int k, int par) { if(d == k) return v; if(adj[v].size() == 1) return dfs(adj[v][i].first,d+1,k,v); else { int mx = 0; int mxver; for(int i = 0; i < adj[v].size(); i++) { int u = adj[v][i].first; int bt = adj[v][i].second; if(u != par) { if(bt > mx) { mx = bt; mxver = u; } } } return dfs(mxver,d+1,k,v); } } void count_routes(int N, int M, int P, int R[][2], int Q, int G[]) { for(int i = 0; i < M; i++) { int v = R[i][0], u = R[i][1], beauty = M - i; adj[v].push_back(make_pair(u,beauty)); adj[u].push_back(make_pair(v,beauty)); } int res = 0; for(int i = 0; i < n; i++) { if(dfs(i,0,G[0],-1) == P) res++; } for(int i=0; i<Q; i++) answer(res); }