답안 #197842

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
197842 2020-01-23T15:44:59 Z arnold518 Split the Attractions (IOI19_split) C++14
100 / 100
246 ms 25952 KB
#include "split.h"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 1e5;

int N, ans[MAXN+10];
pii A[4];
vector<int> adj[MAXN+10], adj2[MAXN+10], adj3[MAXN+10];
	
int sz[MAXN+10], id[MAXN+10];

void getsz(int now, int bef)
{
	sz[now]=1;
	for(int nxt : adj2[now])
	{
		if(nxt==bef) continue;
		getsz(nxt, now);
		sz[now]+=sz[nxt];
	}
}

int getcen(int now, int bef, int S)
{
	for(int nxt : adj2[now])
	{
		if(nxt==bef) continue;
		if(sz[nxt]>S/2) return getcen(nxt, now, S);
	}
	return now;
}

void color(int now, int bef, int col, int &k)
{
	if(k<=0) return;
	ans[now]=col; k--;
	for(int nxt : adj2[now])
	{
		if(nxt==bef) continue;
		if(ans[nxt]) continue;
		color(nxt, now, col, k);
	}
}

void color2(int now, int bef, int root)
{
	id[now]=root;
	for(int nxt : adj2[now])
	{
		if(nxt==bef) continue;
		color2(nxt, now, root);
	}
}

bool vis[MAXN+10];
void dfs(int now)
{
	vis[now]=true;
	for(int nxt : adj[now])
	{
		if(vis[nxt]) continue;
		adj2[now].push_back(nxt);
		adj2[nxt].push_back(now);
		dfs(nxt);
	}
}

vector<int> V;
void dfs2(int now, int &k)
{
	vis[now]=true;
	k+=sz[now]; V.push_back(now);
	if(k>=A[1].first) return;
	for(int nxt : adj3[now])
	{
		if(vis[nxt]) continue;
		dfs2(nxt, k);
	}
}

void solve()
{
	int i, j;

	memset(vis, 0, sizeof(vis));
	dfs(1);
	getsz(1, 1);
	int cen=getcen(1, 1, N);
	getsz(cen, cen);

	for(int now : adj2[cen])
	{
		color2(now, cen, now);
		if(A[1].first<=sz[now])
		{
			int t=A[1].first;
			color(now, cen, A[1].second, t);
			t=A[2].first;
			color(cen, now, A[2].second, t);
			for(i=1; i<=N; i++) if(ans[i]==0) ans[i]=A[3].second;
			return;
		}
	}

	for(i=1; i<=N; i++)
	{
		int now=i;
		if(now==cen) continue;
		for(int nxt : adj[now])
		{
			if(nxt==cen) continue;
			if(id[now]==id[nxt]) continue;
			adj3[id[now]].push_back(id[nxt]);
		}
	}

	memset(vis, 0, sizeof(vis));
	for(int now : adj2[cen])
	{
		if(vis[now]) continue;
		int t=0;
		dfs2(now, t);
		if(t<A[1].first) continue;

		t=A[1].first;
		for(auto it : V) color(it, cen, A[1].second, t);
		color(cen, cen, A[2].second, A[2].first);
		for(i=1; i<=N; i++) if(ans[i]==0) ans[i]=A[3].second;
		return;
	}
}

vector<int> find_split(int _N, int _A, int _B, int _C, vector<int> _P, vector<int> _Q)
{
	int i, j;
	N=_N; A[1]=pii(_A, 1); A[2]=pii(_B, 2); A[3]=pii(_C, 3);
	for(i=0; i<_P.size(); i++)
	{
		int u=_P[i]+1, v=_Q[i]+1;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	sort(A+1, A+4);

	solve();

	vector<int> _ans(N);
	for(i=1; i<=N; i++) _ans[i-1]=ans[i];
	return _ans;
}

Compilation message

split.cpp: In function 'void solve()':
split.cpp:88:9: warning: unused variable 'j' [-Wunused-variable]
  int i, j;
         ^
split.cpp: In function 'std::vector<int> find_split(int, int, int, int, std::vector<int>, std::vector<int>)':
split.cpp:142:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(i=0; i<_P.size(); i++)
           ~^~~~~~~~~~
split.cpp:140:9: warning: unused variable 'j' [-Wunused-variable]
  int i, j;
         ^
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 7544 KB ok, correct split
2 Correct 15 ms 7544 KB ok, correct split
3 Correct 9 ms 7544 KB ok, correct split
4 Correct 10 ms 7544 KB ok, correct split
5 Correct 8 ms 7416 KB ok, correct split
6 Correct 8 ms 7416 KB ok, correct split
7 Correct 179 ms 22776 KB ok, correct split
8 Correct 168 ms 21260 KB ok, correct split
9 Correct 182 ms 20268 KB ok, correct split
10 Correct 179 ms 23160 KB ok, correct split
11 Correct 185 ms 23164 KB ok, correct split
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 7416 KB ok, correct split
2 Correct 8 ms 7416 KB ok, correct split
3 Correct 9 ms 7416 KB ok, correct split
4 Correct 201 ms 20808 KB ok, correct split
5 Correct 143 ms 17144 KB ok, correct split
6 Correct 172 ms 23160 KB ok, correct split
7 Correct 182 ms 20856 KB ok, correct split
8 Correct 215 ms 18808 KB ok, correct split
9 Correct 160 ms 16888 KB ok, correct split
10 Correct 119 ms 17244 KB ok, correct split
11 Correct 105 ms 17264 KB ok, correct split
12 Correct 116 ms 17216 KB ok, correct split
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 7416 KB ok, correct split
2 Correct 156 ms 17012 KB ok, correct split
3 Correct 54 ms 11384 KB ok, correct split
4 Correct 9 ms 7416 KB ok, correct split
5 Correct 188 ms 18976 KB ok, correct split
6 Correct 178 ms 18680 KB ok, correct split
7 Correct 182 ms 18796 KB ok, correct split
8 Correct 190 ms 19832 KB ok, correct split
9 Correct 179 ms 18780 KB ok, correct split
10 Correct 44 ms 10616 KB ok, no valid answer
11 Correct 66 ms 12136 KB ok, no valid answer
12 Correct 127 ms 17396 KB ok, no valid answer
13 Correct 150 ms 16892 KB ok, no valid answer
14 Correct 111 ms 17796 KB ok, no valid answer
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 7544 KB ok, correct split
2 Correct 5 ms 7416 KB ok, no valid answer
3 Correct 10 ms 7416 KB ok, correct split
4 Correct 8 ms 7416 KB ok, correct split
5 Correct 8 ms 7408 KB ok, correct split
6 Correct 9 ms 7416 KB ok, correct split
7 Correct 9 ms 7416 KB ok, correct split
8 Correct 9 ms 7416 KB ok, correct split
9 Correct 11 ms 7800 KB ok, correct split
10 Correct 12 ms 7800 KB ok, correct split
11 Correct 9 ms 7420 KB ok, correct split
12 Correct 13 ms 7800 KB ok, correct split
13 Correct 8 ms 7416 KB ok, correct split
14 Correct 9 ms 7416 KB ok, correct split
15 Correct 9 ms 7544 KB ok, correct split
16 Correct 8 ms 7516 KB ok, correct split
17 Correct 8 ms 7416 KB ok, correct split
18 Correct 9 ms 7416 KB ok, correct split
19 Correct 9 ms 7544 KB ok, correct split
20 Correct 12 ms 7548 KB ok, correct split
21 Correct 11 ms 7720 KB ok, correct split
22 Correct 14 ms 7800 KB ok, correct split
23 Correct 11 ms 7800 KB ok, correct split
24 Correct 14 ms 7800 KB ok, correct split
25 Correct 11 ms 7800 KB ok, correct split
26 Correct 12 ms 8056 KB ok, correct split
27 Correct 11 ms 7928 KB ok, correct split
28 Correct 12 ms 7928 KB ok, correct split
29 Correct 9 ms 7544 KB ok, correct split
30 Correct 11 ms 7800 KB ok, correct split
31 Correct 10 ms 7544 KB ok, correct split
32 Correct 7 ms 7516 KB ok, correct split
33 Correct 9 ms 7544 KB ok, correct split
34 Correct 11 ms 7800 KB ok, correct split
35 Correct 16 ms 7800 KB ok, correct split
36 Correct 11 ms 7672 KB ok, correct split
37 Correct 15 ms 7928 KB ok, correct split
38 Correct 10 ms 7900 KB ok, correct split
39 Correct 12 ms 7928 KB ok, correct split
40 Correct 12 ms 7800 KB ok, correct split
41 Correct 11 ms 7672 KB ok, correct split
42 Correct 10 ms 7676 KB ok, correct split
43 Correct 12 ms 7880 KB ok, correct split
44 Correct 12 ms 7800 KB ok, correct split
45 Correct 12 ms 7800 KB ok, correct split
46 Correct 11 ms 7924 KB ok, correct split
47 Correct 11 ms 7800 KB ok, no valid answer
48 Correct 11 ms 7800 KB ok, correct split
49 Correct 11 ms 7800 KB ok, correct split
50 Correct 9 ms 7416 KB ok, no valid answer
51 Correct 9 ms 7544 KB ok, no valid answer
52 Correct 11 ms 7800 KB ok, no valid answer
53 Correct 13 ms 7800 KB ok, no valid answer
54 Correct 10 ms 7800 KB ok, no valid answer
55 Correct 30 ms 7772 KB ok, no valid answer
56 Correct 11 ms 7800 KB ok, no valid answer
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 7544 KB ok, correct split
2 Correct 15 ms 7544 KB ok, correct split
3 Correct 9 ms 7544 KB ok, correct split
4 Correct 10 ms 7544 KB ok, correct split
5 Correct 8 ms 7416 KB ok, correct split
6 Correct 8 ms 7416 KB ok, correct split
7 Correct 179 ms 22776 KB ok, correct split
8 Correct 168 ms 21260 KB ok, correct split
9 Correct 182 ms 20268 KB ok, correct split
10 Correct 179 ms 23160 KB ok, correct split
11 Correct 185 ms 23164 KB ok, correct split
12 Correct 9 ms 7416 KB ok, correct split
13 Correct 8 ms 7416 KB ok, correct split
14 Correct 9 ms 7416 KB ok, correct split
15 Correct 201 ms 20808 KB ok, correct split
16 Correct 143 ms 17144 KB ok, correct split
17 Correct 172 ms 23160 KB ok, correct split
18 Correct 182 ms 20856 KB ok, correct split
19 Correct 215 ms 18808 KB ok, correct split
20 Correct 160 ms 16888 KB ok, correct split
21 Correct 119 ms 17244 KB ok, correct split
22 Correct 105 ms 17264 KB ok, correct split
23 Correct 116 ms 17216 KB ok, correct split
24 Correct 9 ms 7416 KB ok, correct split
25 Correct 156 ms 17012 KB ok, correct split
26 Correct 54 ms 11384 KB ok, correct split
27 Correct 9 ms 7416 KB ok, correct split
28 Correct 188 ms 18976 KB ok, correct split
29 Correct 178 ms 18680 KB ok, correct split
30 Correct 182 ms 18796 KB ok, correct split
31 Correct 190 ms 19832 KB ok, correct split
32 Correct 179 ms 18780 KB ok, correct split
33 Correct 44 ms 10616 KB ok, no valid answer
34 Correct 66 ms 12136 KB ok, no valid answer
35 Correct 127 ms 17396 KB ok, no valid answer
36 Correct 150 ms 16892 KB ok, no valid answer
37 Correct 111 ms 17796 KB ok, no valid answer
38 Correct 9 ms 7544 KB ok, correct split
39 Correct 5 ms 7416 KB ok, no valid answer
40 Correct 10 ms 7416 KB ok, correct split
41 Correct 8 ms 7416 KB ok, correct split
42 Correct 8 ms 7408 KB ok, correct split
43 Correct 9 ms 7416 KB ok, correct split
44 Correct 9 ms 7416 KB ok, correct split
45 Correct 9 ms 7416 KB ok, correct split
46 Correct 11 ms 7800 KB ok, correct split
47 Correct 12 ms 7800 KB ok, correct split
48 Correct 9 ms 7420 KB ok, correct split
49 Correct 13 ms 7800 KB ok, correct split
50 Correct 8 ms 7416 KB ok, correct split
51 Correct 9 ms 7416 KB ok, correct split
52 Correct 9 ms 7544 KB ok, correct split
53 Correct 8 ms 7516 KB ok, correct split
54 Correct 8 ms 7416 KB ok, correct split
55 Correct 9 ms 7416 KB ok, correct split
56 Correct 9 ms 7544 KB ok, correct split
57 Correct 12 ms 7548 KB ok, correct split
58 Correct 11 ms 7720 KB ok, correct split
59 Correct 14 ms 7800 KB ok, correct split
60 Correct 11 ms 7800 KB ok, correct split
61 Correct 14 ms 7800 KB ok, correct split
62 Correct 11 ms 7800 KB ok, correct split
63 Correct 12 ms 8056 KB ok, correct split
64 Correct 11 ms 7928 KB ok, correct split
65 Correct 12 ms 7928 KB ok, correct split
66 Correct 9 ms 7544 KB ok, correct split
67 Correct 11 ms 7800 KB ok, correct split
68 Correct 10 ms 7544 KB ok, correct split
69 Correct 7 ms 7516 KB ok, correct split
70 Correct 9 ms 7544 KB ok, correct split
71 Correct 11 ms 7800 KB ok, correct split
72 Correct 16 ms 7800 KB ok, correct split
73 Correct 11 ms 7672 KB ok, correct split
74 Correct 15 ms 7928 KB ok, correct split
75 Correct 10 ms 7900 KB ok, correct split
76 Correct 12 ms 7928 KB ok, correct split
77 Correct 12 ms 7800 KB ok, correct split
78 Correct 11 ms 7672 KB ok, correct split
79 Correct 10 ms 7676 KB ok, correct split
80 Correct 12 ms 7880 KB ok, correct split
81 Correct 12 ms 7800 KB ok, correct split
82 Correct 12 ms 7800 KB ok, correct split
83 Correct 11 ms 7924 KB ok, correct split
84 Correct 11 ms 7800 KB ok, no valid answer
85 Correct 11 ms 7800 KB ok, correct split
86 Correct 11 ms 7800 KB ok, correct split
87 Correct 9 ms 7416 KB ok, no valid answer
88 Correct 9 ms 7544 KB ok, no valid answer
89 Correct 11 ms 7800 KB ok, no valid answer
90 Correct 13 ms 7800 KB ok, no valid answer
91 Correct 10 ms 7800 KB ok, no valid answer
92 Correct 30 ms 7772 KB ok, no valid answer
93 Correct 11 ms 7800 KB ok, no valid answer
94 Correct 181 ms 20568 KB ok, correct split
95 Correct 246 ms 25144 KB ok, correct split
96 Correct 225 ms 23704 KB ok, correct split
97 Correct 52 ms 11768 KB ok, correct split
98 Correct 57 ms 11896 KB ok, correct split
99 Correct 72 ms 13944 KB ok, correct split
100 Correct 219 ms 21880 KB ok, correct split
101 Correct 196 ms 20728 KB ok, correct split
102 Correct 185 ms 20336 KB ok, correct split
103 Correct 161 ms 19952 KB ok, correct split
104 Correct 159 ms 21988 KB ok, correct split
105 Correct 95 ms 14372 KB ok, correct split
106 Correct 187 ms 25952 KB ok, correct split
107 Correct 159 ms 18296 KB ok, correct split
108 Correct 155 ms 18296 KB ok, correct split
109 Correct 234 ms 21112 KB ok, correct split
110 Correct 217 ms 22136 KB ok, correct split
111 Correct 231 ms 22164 KB ok, correct split
112 Correct 208 ms 22404 KB ok, correct split
113 Correct 204 ms 22360 KB ok, correct split
114 Correct 23 ms 9284 KB ok, correct split
115 Correct 22 ms 8952 KB ok, correct split
116 Correct 220 ms 22152 KB ok, correct split
117 Correct 225 ms 22008 KB ok, correct split
118 Correct 164 ms 18168 KB ok, correct split
119 Correct 167 ms 18040 KB ok, correct split
120 Correct 177 ms 21496 KB ok, correct split
121 Correct 145 ms 17784 KB ok, no valid answer
122 Correct 213 ms 18100 KB ok, no valid answer
123 Correct 237 ms 21496 KB ok, no valid answer
124 Correct 243 ms 21528 KB ok, no valid answer
125 Correct 151 ms 19628 KB ok, no valid answer
126 Correct 104 ms 17780 KB ok, no valid answer
127 Correct 172 ms 20208 KB ok, no valid answer