Submission #411046

# Submission time Handle Problem Language Result Execution time Memory
411046 2021-05-24T07:49:05 Z nxteru Tropical Garden (IOI11_garden) C++14
100 / 100
2968 ms 35964 KB
#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],dd[300005][2];
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++){
		for(int j=0;j<2;j++){
			dd[i][j]=d[j][fi[i]];
		}
	}
	for(int i=0;i<q;i++){
		int ans=0,x=G[i];
		for(int j=0;j<n;j++){
			bool ok=false;
			for(int l=0;l<2;l++)if(dd[j][l]==x||(rp[t[l]]&&dd[j][l]<=x&&(x-dd[j][l])%sz[t[l]]==0))ok=true;
			if(ok)ans++;
		}
		answer(ans);
	}
}

Compilation message

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 time Memory Grader output
1 Correct 6 ms 10956 KB Output is correct
2 Correct 7 ms 10956 KB Output is correct
3 Correct 7 ms 11088 KB Output is correct
4 Correct 6 ms 10828 KB Output is correct
5 Correct 6 ms 10828 KB Output is correct
6 Correct 8 ms 11084 KB Output is correct
7 Correct 6 ms 10952 KB Output is correct
8 Correct 7 ms 11016 KB Output is correct
9 Correct 12 ms 11600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 10956 KB Output is correct
2 Correct 7 ms 10956 KB Output is correct
3 Correct 7 ms 11088 KB Output is correct
4 Correct 6 ms 10828 KB Output is correct
5 Correct 6 ms 10828 KB Output is correct
6 Correct 8 ms 11084 KB Output is correct
7 Correct 6 ms 10952 KB Output is correct
8 Correct 7 ms 11016 KB Output is correct
9 Correct 12 ms 11600 KB Output is correct
10 Correct 6 ms 10828 KB Output is correct
11 Correct 20 ms 14220 KB Output is correct
12 Correct 38 ms 17508 KB Output is correct
13 Correct 61 ms 23956 KB Output is correct
14 Correct 116 ms 30980 KB Output is correct
15 Correct 157 ms 31592 KB Output is correct
16 Correct 150 ms 27920 KB Output is correct
17 Correct 137 ms 27144 KB Output is correct
18 Correct 38 ms 17608 KB Output is correct
19 Correct 116 ms 30976 KB Output is correct
20 Correct 158 ms 31636 KB Output is correct
21 Correct 148 ms 27992 KB Output is correct
22 Correct 136 ms 27012 KB Output is correct
23 Correct 115 ms 32380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 10956 KB Output is correct
2 Correct 7 ms 10956 KB Output is correct
3 Correct 7 ms 11088 KB Output is correct
4 Correct 6 ms 10828 KB Output is correct
5 Correct 6 ms 10828 KB Output is correct
6 Correct 8 ms 11084 KB Output is correct
7 Correct 6 ms 10952 KB Output is correct
8 Correct 7 ms 11016 KB Output is correct
9 Correct 12 ms 11600 KB Output is correct
10 Correct 6 ms 10828 KB Output is correct
11 Correct 20 ms 14220 KB Output is correct
12 Correct 38 ms 17508 KB Output is correct
13 Correct 61 ms 23956 KB Output is correct
14 Correct 116 ms 30980 KB Output is correct
15 Correct 157 ms 31592 KB Output is correct
16 Correct 150 ms 27920 KB Output is correct
17 Correct 137 ms 27144 KB Output is correct
18 Correct 38 ms 17608 KB Output is correct
19 Correct 116 ms 30976 KB Output is correct
20 Correct 158 ms 31636 KB Output is correct
21 Correct 148 ms 27992 KB Output is correct
22 Correct 136 ms 27012 KB Output is correct
23 Correct 115 ms 32380 KB Output is correct
24 Correct 7 ms 10828 KB Output is correct
25 Correct 124 ms 14240 KB Output is correct
26 Correct 181 ms 17516 KB Output is correct
27 Correct 2528 ms 24092 KB Output is correct
28 Correct 1255 ms 32704 KB Output is correct
29 Correct 2968 ms 33476 KB Output is correct
30 Correct 1662 ms 29532 KB Output is correct
31 Correct 1698 ms 28716 KB Output is correct
32 Correct 164 ms 18244 KB Output is correct
33 Correct 1238 ms 32684 KB Output is correct
34 Correct 2929 ms 33432 KB Output is correct
35 Correct 1772 ms 29556 KB Output is correct
36 Correct 1700 ms 28604 KB Output is correct
37 Correct 956 ms 34252 KB Output is correct
38 Correct 2391 ms 35964 KB Output is correct