답안 #62884

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
62884 2018-07-30T16:26:17 Z reality 열대 식물원 (Tropical Garden) (IOI11_garden) C++17
0 / 100
14 ms 12280 KB
#include "garden.h"
#include "gardenlib.h"
#include "bits/stdc++.h"
using namespace std;
#define fi first
#define se second
#define ll long long
#define dbg(v) cerr<<#v<<" = "<<v<<'\n'
#define vi vector<int>
#define vl vector <ll>
#define pii pair<int,int>
#define mp make_pair
#define db long double
#define pb push_back
#define all(s) s.begin(),s.end()
template < class T > T smin(T &a,T b) {if (a > b) a = b;return a;}
template < class T > T smax(T &a,T b) {if (a < b) a = b;return a;}

const int NN = 5e5 + 5;

int f[NN];

int deg[NN];

int Deg[NN];

int was[NN];

int D[NN][2];

vi g[NN];

void dfs(int node,int w) {
	for (auto it : g[node])
		if (D[it][w] == -1) {
			D[it][w] = D[node][w] + 1;
			dfs(it,w);
		}
}


void count_routes(int N, int M, int P, int R[][2], int Q, int G[]) {
	vector < pii > e;
	int n = N;
	for (int i = 0;i < n + n;++i)
		f[i] = -1;
	for (int i = 0;i < M;++i) {
		int u = R[i][0];
		int v = R[i][1];
		++Deg[u];
		++Deg[v];
		smin(Deg[u],2);
		smin(Deg[v],2);
	}
	for (int i = 0;i < M;++i) {
		int u = R[i][0];
		int v = R[i][1];
		++deg[u];
		++deg[v];
		for (int cs = 0;cs < 2;++cs) {
			if (deg[u] == 1) {
				if (deg[v] >= Deg[v])
					f[u * 2] = v * 2;
				else
					f[u * 2] = v * 2 + 1;
			}
			else
			if (deg[u] == 2) {
				if (deg[v] >= Deg[v])
					f[u * 2 + 1] = v * 2;
				else
					f[u * 2 + 1] = v * 2 + 1;
			}
			swap(u,v);
		}
	}
	
	for (int i = 0;i < n + n;++i)
		if (f[i] != -1) {
			g[f[i]].pb(i);
		}
	for (int i = 0;i < n + n;++i)
		for (int t = 0;t < 2;++t)
			D[i][t] = -1;
	D[P * 2][0] = 0;
	D[P * 2 + 1][1] = 0;
	dfs(P * 2,0);
	dfs(P * 2 + 1,1);
	int cycle[2] = {-1,-1};
	for (int t = 0;t < 2;++t) {
		int cnt = P * 2 + t;
		for (int i = 0;i < n + n;++i)
			was[i] = 0;
		int vis = 0;
		while (!was[cnt]) {
			++vis;
			was[cnt] = 1;
			cnt = f[cnt];
		}
		if (cnt == P * 2 + t)
			cycle[t] = vis;
	}
	for (int i = 0;i < Q;++i) {
		int ans = 0;
		for (int j = 0;j < n + n;j += 2) {
			int ok = 0;
			for (int t = 0;t < 2;++t) {
				if (G[i] == D[j][t])
					ok = 1;
				else 
				if (cycle[t] != -1) {
					ok |= (D[j][t] <= G[i]) && !((G[i] - D[j][t]) % cycle[t]);
				}
			}
			ans += ok;
		}
		answer(ans);
	}
}


# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 12280 KB Output is correct
2 Correct 14 ms 12196 KB Output is correct
3 Incorrect 13 ms 12280 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 12280 KB Output is correct
2 Correct 14 ms 12196 KB Output is correct
3 Incorrect 13 ms 12280 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 12280 KB Output is correct
2 Correct 14 ms 12196 KB Output is correct
3 Incorrect 13 ms 12280 KB Output isn't correct
4 Halted 0 ms 0 KB -