답안 #62871

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
62871 2018-07-30T15:19:00 Z reality 열대 식물원 (Tropical Garden) (IOI11_garden) C++17
0 / 100
3 ms 340 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];

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];
		smin(deg[u],2);
		smin(deg[v],2);
		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);
		}
	}
	auto go = [&](int cnt,int cur) {
		while (cnt > 0 && cur >= 0) {
			--cnt;
			cur = f[cur];
		}
		return (cur / 2) == P;
	};
	for (int i = 0;i < Q;++i) {
		int ans = 0;
		for (int j = 0;j < n + n;j += 2) {
			ans += go(G[i],j) || go(G[i],j + 1);
		}
		answer(ans);
	}
}


# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -