Submission #1092129

#TimeUsernameProblemLanguageResultExecution timeMemory
1092129AvianshTropical Garden (IOI11_garden)C++17
0 / 100
1 ms604 KiB
#include <bits/stdc++.h> #include "garden.h" #include "gardenlib.h" using namespace std; void dfs(int st, int dep, vector<int>(&g)[], int f[], bool vis[], int t, int p, int n){ vis[st]=1; f[st]=dep; if(g[st].size()==0){ if(p>n){ p-=n; } else{ p+=n; } if(!vis[p]){ dfs(p,dep+1,g,f,vis,t,st, n); } } for(int i : g[st]){ if(i==t){ f[t]=dep+1; } if(vis[i]) continue; dfs(i,dep+1,g,f,vis,t, st, n); } } void count_routes(int n, int m, int t, int edges[][2], int q, int G[]) { vector<int>g[2*n]; int cn[n]; fill(cn,cn+n,0); for(int i = 0;i<m;i++){ int u1=edges[i][0]; int v1=edges[i][1]; //cout << u1 << " " << v1 << endl; if(cn[u1]>cn[v1]){ swap(u1,v1); } int u2 = u1+n; int v2 = v1+n; if(cn[u1]==0&&cn[v1]==0){ //cout << "adding1: " << u1 << " " << v2 << endl; //cout << "adding2: " << v1 << " " << u2 << endl; g[v2].push_back(u1); g[u2].push_back(v1); } else if(cn[u1]==0&&cn[v1]==1){ // cout << "adding3: " << u1 << " " << v1 << endl; // cout << "adding4: " << v2 << " " << u2 << endl; g[v1].push_back(u1); g[u2].push_back(v2); } else if(cn[u1]==0&&cn[v1]>1){ // cout << "adding5: " << u1 << " " << v1 << endl; g[v1].push_back(u1); } else if(cn[u1]==1&&cn[v1]==1){ // cout << "adding6: " << u2 << " " << v1 << endl; // cout << "adding7: " << v2 << " " << u1 << endl; g[v1].push_back(u2); g[u1].push_back(v2); } else if(cn[u1]==1&&cn[v1]>1){ // cout << "adding8: " << u2 << " " << v1 << endl;; g[v1].push_back(u2); } cn[u1]++; cn[v1]++; } int f1[2*n]; fill(f1,f1+2*n,-1); bool vis[2*n]; fill(vis,vis+2*n,0); dfs(t,0,g,f1,vis,t,-1, n); int f2[2*n]; fill(f2,f2+2*n,-1); fill(vis,vis+2*n,0); dfs(t+n,0,g,f2,vis,t,-1, n); for(int i = 0;i<q;i++){ int ans = 0; // cout << "here" << endl; // cout << "going in" << endl; for(int j = 0;j<n;j++){ // cout << "inside loop now2" << endl; // cout << i << " " << j << " " << t << " " << n << " " << f1[t] << " " << f1[j] << " " << f2[j] << " " << f2[t+n] <<endl; if(f1[j]==G[i]||(f1[t]!=0&&f1[j]!=-1&&f1[j]<=G[i]&&f1[j]%f1[t]==G[i]%f1[t])){ ans++; // cout << "added 1" << endl; } // cout << "outside first if" << endl; if(f2[j]==G[i]||(f2[t+n]!=0&&f2[j]!=-1&&f2[j]<=G[i]&&f2[j]%f2[t+n]==G[i]%f2[t+n])){ ans++; // cout << "added 1 next" << endl; } } //cout << "answering..."; answer(ans); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...