# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
269202 | 2020-08-17T05:40:56 Z | Autoratch | Tropical Garden (IOI11_garden) | C++14 | 13 ms | 14440 KB |
#include "garden.h" #include "gardenlib.h" #include <bits/stdc++.h> using namespace std; const int N = 2e5; vector<pair<int,int> > adj[N]; pair<int,int> ed[N << 1]; vector<int> res[N << 1]; queue<tuple<int,int,int,int> > q; void bfs() { while(!q.empty()) { auto [u,p,id,cnt] = q.front(); q.pop(); if(res[id].size()>=20) continue; // if(cnt>100) continue; if(u!=p and p==adj[u][0].second) res[id].push_back(cnt); if(id==-1 or adj[u][0].second==p) { for(auto [w,v] : adj[u]) if(v!=p or adj[u].size()==1) q.push({v,u,w,cnt+1}); } else if(adj[u][1].second==p) { auto [w,v] = adj[u][0]; if(v!=p) q.push({v,u,w,cnt+1}); } } } void dfs(int u,int p,int id,int cnt) { q.push({u,p,id,cnt}); bfs(); return; if(res[id].size()>=5) return; res[id].push_back(cnt); if(id==-1 or adj[u][0].second==p) { for(auto [w,v] : adj[u]) if(v!=p or adj[u].size()==1) dfs(v,u,w,cnt+1); } else if(adj[u][1].second==p) { auto [w,v] = adj[u][0]; if(v!=p) dfs(v,u,w,cnt+1); } } void count_routes(int n,int m,int p,int r[][2],int q,int g[]) { for(int i = 0,j = 0;i < m;i++) { int a = r[i][0],b = r[i][1]; ed[j] = {a,b}; adj[a].push_back({j++,b}); ed[j] = {b,a}; adj[b].push_back({j++,a}); } dfs(p,p,-1,0); for(int i = 0;i < q;i++) { int ans = 0; for(int j = 0;j < m*2;j++)// for(int x : res[j]) if(x==g[i]) ans++; { if(res[j].size()>0 and res[j][0]==g[i]) ans++; else if(res[j].size()>2 and ((g[i]-res[j][1])%(res[j][2]-res[j][1]))==0) ans++; } answer(ans); } return; for(int i = 0;i < m*2;i++) { cout << ed[i].first << ' ' << ed[i].second << endl; for(int x : res[i]) cout << x << ' ' ; cout << endl; } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 13 ms | 14440 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 13 ms | 14440 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 13 ms | 14440 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |