Submission #123076

#TimeUsernameProblemLanguageResultExecution timeMemory
123076nxteruTropical Garden (IOI11_garden)C++14
0 / 100
12 ms11068 KiB
#include "garden.h" #include "gardenlib.h" #include <bits/stdc++.h> using namespace std; typedef pair<int,int> P; #define F first #define S second #define PB push_back int n,m,q,k,nx[300005],t[2],fi[150005],vis[300005],sz[300005],d[2][300005]; vector<P>e[150005]; vector<int>g[300005]; bool rp[300005]; void dfs(int v,int cn){ vis[v]=k; sz[v]=cn; int u=nx[v]; if(vis[u]==-1)dfs(u,cn+1); else if(vis[u]==k){ int s=sz[u]+1-cn; u=v; do{ u=nx[u]; rp[u]=true; sz[u]=s; }while(u!=v); } } void count_routes(int N, int M, int p, int R[][2], int Q, int G[]){ n=N,m=M,q=Q; for(int i=0;i<m;i++){ int a=R[i][0],b=R[i][1]; e[a].PB(P(i,0)); e[b].PB(P(i,1)); } for(int i=0;i<m;i++){ int a=R[i][0],b=R[i][1]; if(e[b].size()==1||e[b][0].F!=i)nx[i*2]=e[b][0].F*2+e[b][0].S; else nx[i*2]=e[b][1].F*2+e[b][1].S; if(e[a].size()==1||e[a][0].F!=i)nx[i*2+1]=e[a][0].F*2+e[a][0].S; else nx[i*2+1]=e[a][1].F*2+e[a][1].S; } for(int i=0;i<n;i++)fi[i]=e[i][0].F*2+e[i][0].S; t[0]=fi[p]; if(e[p].size()>1)t[1]=e[p][1].F*2+e[p][1].S; else t[1]=t[0]; for(int i=0;i<m*2;i++)vis[i]=-1; for(int i=0;i<m*2;i++){ if(vis[i]==-1){ dfs(i,0); k++; } } for(int i=0;i<m*2;i++)g[nx[i]].PB(i); for(int i=0;i<2;i++){ for(int j=0;j<m*2;j++)d[i][j]=-1; d[i][t[i]]=0; queue<int>bfs; bfs.push(t[i]); while(!bfs.empty()){ int v=bfs.front(),c=d[i][v]; bfs.pop(); for(int j=0;j<g[v].size();j++){ int u=g[v][j]; if(d[i][u]==-1){ d[i][u]=c+1; bfs.push(u); } } } } for(int i=0;i<q;i++){ int ans=0,x=G[i]; for(int j=0;j<n;j++){ int v=fi[j]; bool ok=false; for(int l=0;l<2;l++){ if(d[l][v]==x||(rp[t[l]]&&d[l][v]<=x&&(x-d[l][v])%sz[t[l]]==0))ok=true; } if(ok)ans++; } answer(ans); } }

Compilation message (stderr)

garden.cpp: In function 'void count_routes(int, int, int, int (*)[2], int, int*)':
garden.cpp:62:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(int j=0;j<g[v].size();j++){
                ~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...