Submission #411035

#TimeUsernameProblemLanguageResultExecution timeMemory
411035nxteruTropical Garden (IOI11_garden)C++14
0 / 100
7 ms11084 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 #define INF 1000000001 int n,m,q,k,nx[300005],t[2],fi[150005],vis[300005],sz[300005],d[2][300005],d0[300005],d1[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=cn-sz[u]+1; 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]=INF; 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]==INF){ d[i][u]=c+1; bfs.push(u); } } } } for(int i=0;i<n;i++){ d0[i]=d[0][fi[i]]; d1[i]=d[1][fi[i]]; } for(int i=0;i<q;i++){ int ans=0,x=G[i],t0=t[0],t1=t[1]; for(int j=0;j<n;j++){ if(d0[j]<=x&&(x-d0[j])%sz[t0]==0)ans++; } for(int j=0;j<n;j++){ if(d1[j]<=x&&(x-d1[j])%sz[t1]==0)ans++; } answer(ans); } }

Compilation message (stderr)

garden.cpp: In function 'void count_routes(int, int, int, int (*)[2], int, int*)':
garden.cpp:63:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |    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...