Submission #415318

# Submission time Handle Problem Language Result Execution time Memory
415318 2021-05-31T21:34:03 Z CSQ31 Tropical Garden (IOI11_garden) C++14
0 / 100
12 ms 19424 KB
#include "garden.h"
#include <bits/stdc++.h>
#include "gardenlib.h"
using namespace std;
#define sz(a) (int)(a.size())
#define pb push_back
#define se second
typedef vector<vector<int>> vii;
typedef pair<int,int> pii;
const int MAXN = 4e5+5;
int nxt[MAXN][31];
vector<vector<pii>> g1(MAXN);
vii g2(MAXN);
void count_routes(int n, int m, int p, int r[][2], int q, int g[])
{
	for(int i=0;i<m;i++){
		g1[r[i][0]].pb({i,r[i][1]});
		g1[r[i][1]].pb({i,r[i][0]});
	}
	for(int i=0;i<n;i++)sort(g1[i].begin(),g1[i].end());
	for(int i=0;i<n;i++){
		int to = g1[i][0].se;
		if(g1[to][0].se != i){
			nxt[i][0] = to; //not beautiful
			g2[to].pb(i);
		}
		else {
			nxt[i][0] = to+n;
			g2[to+n].pb(i);
		}
		
		to = (sz(g1[i]) > 1)?g1[i][1].se:g1[i][0].se;
		if(g1[to][0].se != i){
			nxt[i+n][0] = to; //not beautiful
			g2[to].pb(i+n);
		}
		else {
			nxt[i+n][0] = to+n;
			g2[to+n].pb(i+n);
		}
	}
	vector<int>cycle(2*n),vis(2*n);
	int i = 0;
	while(!vis[i]){
		vis[i] = 1;
		i = nxt[i][0];
	}
	int len = 0;
	while(!cycle[i]){
		cycle[i] = 1;
		len++;
		i = nxt[i][0];
	}
	vii d(2,vector<int>(2*n,2e9));
	queue<int>qq;
	qq.push(p);
	d[0][p] = 0;
	vis.assign(2*n,0);
	vis[p] = 1;
	while(!qq.empty()){
		int v = qq.front();
		qq.pop();
		for(int x:g2[v]){
			if(vis[x])continue;
			vis[x] =1;
			d[0][x] = d[0][v]+1;
			qq.push(x);
		}
	}
	d[1][p+n] = 0;
	qq.push(p+n);
	vis.assign(2*n,0);
	vis[p+n] = 1;
	while(!qq.empty()){
		int v = qq.front();
		qq.pop();
		for(int x:g2[v]){
			if(vis[x])continue;
			vis[x] =1;
			d[1][x] = d[1][v]+1;
			qq.push(x);
		}
	}
	for(int i=0;i<q;i++){
		int ans = 0;
		for(int j=0;j<n;j++){
			if((cycle[p] && g[i] >= d[0][j] && (g[i]-d[0][j])%len == 0) || (cycle[p+n] && g[i] >= d[1][j] && (g[i]-d[1][j])%len == 0) || d[0][j] == g[i] || d[1][j] == g[i])ans++;
		}			
		answer(ans);
	}
}
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 19424 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 19424 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 19424 KB Output isn't correct
2 Halted 0 ms 0 KB -