#include<bits/stdc++.h>
#define vi vector<int>
#define pb push_back
#ifndef local
#include "split.h"
#endif
using namespace std;
const int MXN = 1e5 +5;
int n,a,b,c,m;
vector<int> adj[MXN];
vi case1() {
vector<bool> vis(n);
vis[0] = 1;
queue<int> q;
set<int> sec;
int cnt = b;
q.push(0);
while(!q.empty() && cnt) {
cnt--;
int v = q.front();
sec.insert(v);
q.pop();
for (int i :adj[v]) {
if (!vis[i]) {
vis[i] = 1;
q.push(i);
}
}
}
vector<int> ans(n);
for (int i : sec) ans[i] = 2;
for (int i = 0,flag = 0; i < n; i++) {
if (sec.count(i)) continue;
if (flag == 0) flag = 1, ans[i] = 1;
else ans[i] = 3;
}
return ans;
}
int sz[MXN],flag,X[4],mn,vis[MXN];
set<int> ans[4];
int P[MXN];
void dfs(int v,int p,int type) {
vis[v] = 1;
if (type == 1 && X[flag]) {
X[flag]--;
ans[flag].insert(v);
}
sz[v] = 1;
for (int i : adj[v]) {
if (vis[i] || i == p) continue;
dfs(i,v,type);
sz[v] += sz[i];
}
if (flag) return;
if (sz[v] >= a && n - sz[v] >= min(b,c)) {
flag = 1;
if (n - sz[v] >= b) mn = 2;
else mn = 3;
}
else if (sz[v] >= b && n - sz[v] >= min(a,c)) {
flag = 2;
if (n - sz[v] >= a) mn = 1;
else mn = 3;
}
else if (sz[v] >= c && n - sz[v] >= min(a,b)) {
flag = 3;
if (n - sz[v] >= a) mn = 1;
else mn = 2;
}
else return;
memset(vis,0,sizeof vis);
dfs(v,p,1);
flag = mn;
if (p != -1)
dfs(p,v,1);
}
vi case2() {
int cnt = 0;
vi v,vis(n);
int cur = 0;
while(cnt != n) {
cnt++;
vis[cur] = 1;
v.push_back(cur);
for (int i : adj[cur]) {
if (vis[i]) continue;
cur = i;
break;
}
}
vi ans(n);
if (v.size() != n) {
while(true){
}
}
for (int i = 0; i < a;i++) ans[v[i]] = 1;
for (int i = a; i < a + b; i++) ans[v[i]] = 2;
for (int i = a+b; i < n; i++) ans[v[i]] = 3;
return ans;
}
vi e[MXN];
void soo(int v) {
vis[v] = 1;
for (int i : e[v]) {
if (!vis[i]) {
adj[v].push_back(i);
adj[i].push_back(v);
soo(i);
}
}
}
vector<int> find_split(int n1, int a1, int b1, int c1, vector<int> p, vector<int> q) {
n = n1,a = a1,b=b1,c=c1;
X[1] = a,X[2] = b, X[3] = c;
m = p.size();
for (int i = 0;i < m; i++) {
adj[p[i]].pb(q[i]);
adj[q[i]].pb(p[i]);
}
for (int i = 0;i < n; i++) e[i] = adj[i];
int G = 1;
for (int i = 0; i < n;i++)
if (adj[i].size() != 2) G = 0;
if (G) return case2();
if (a == 1) return case1();
int lim = (n <= 2500 && m <= 5000) ? n : 1;
for (int i = 0;i < lim; i++) {
memset(vis,0,sizeof vis);
for (int i = 0;i < n; i++) adj[i].clear();
soo(i);
memset(vis,0,sizeof vis);
dfs(i,-1,0);
if (flag) break;
}
vector<int> res(n),vis(n);
if (flag == 0) return res;
for (int j = 1; j <= 3; j++)
for (int i : ans[j]) res[i] = j,vis[i] = 1;
int id;
for (int i = 1; i <= 3; i++) if (ans[i].empty()) id = i;
for (int i = 0; i < n; i++) if (!vis[i]) res[i] = id;
return res;
}
Compilation message
split.cpp: In function 'std::vector<int> case2()':
split.cpp:93:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (v.size() != n) {
~~~~~~~~~^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
4992 KB |
ok, correct split |
2 |
Correct |
7 ms |
4992 KB |
ok, correct split |
3 |
Correct |
7 ms |
4992 KB |
ok, correct split |
4 |
Correct |
7 ms |
4992 KB |
ok, correct split |
5 |
Correct |
7 ms |
4992 KB |
ok, correct split |
6 |
Correct |
7 ms |
5120 KB |
ok, correct split |
7 |
Correct |
190 ms |
27620 KB |
ok, correct split |
8 |
Correct |
152 ms |
18168 KB |
ok, correct split |
9 |
Correct |
174 ms |
28256 KB |
ok, correct split |
10 |
Correct |
134 ms |
14424 KB |
ok, correct split |
11 |
Correct |
115 ms |
14448 KB |
ok, correct split |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
4992 KB |
ok, correct split |
2 |
Correct |
7 ms |
4992 KB |
ok, correct split |
3 |
Correct |
8 ms |
5120 KB |
ok, correct split |
4 |
Correct |
98 ms |
14456 KB |
ok, correct split |
5 |
Correct |
107 ms |
15736 KB |
ok, correct split |
6 |
Correct |
94 ms |
14192 KB |
ok, correct split |
7 |
Correct |
118 ms |
15608 KB |
ok, correct split |
8 |
Correct |
145 ms |
17272 KB |
ok, correct split |
9 |
Correct |
112 ms |
15352 KB |
ok, correct split |
10 |
Correct |
101 ms |
16624 KB |
ok, correct split |
11 |
Correct |
93 ms |
16624 KB |
ok, correct split |
12 |
Correct |
116 ms |
16732 KB |
ok, correct split |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
5376 KB |
ok, correct split |
2 |
Correct |
142 ms |
17408 KB |
ok, correct split |
3 |
Correct |
45 ms |
9336 KB |
ok, correct split |
4 |
Correct |
8 ms |
5504 KB |
ok, correct split |
5 |
Correct |
166 ms |
20344 KB |
ok, correct split |
6 |
Correct |
226 ms |
20088 KB |
ok, correct split |
7 |
Correct |
161 ms |
20856 KB |
ok, correct split |
8 |
Correct |
206 ms |
21240 KB |
ok, correct split |
9 |
Correct |
166 ms |
20604 KB |
ok, correct split |
10 |
Correct |
32 ms |
8696 KB |
ok, no valid answer |
11 |
Correct |
55 ms |
10232 KB |
ok, no valid answer |
12 |
Correct |
88 ms |
15092 KB |
ok, no valid answer |
13 |
Correct |
157 ms |
14840 KB |
ok, no valid answer |
14 |
Correct |
80 ms |
15472 KB |
ok, no valid answer |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
5504 KB |
ok, correct split |
2 |
Correct |
8 ms |
5376 KB |
ok, no valid answer |
3 |
Correct |
8 ms |
4992 KB |
ok, correct split |
4 |
Correct |
8 ms |
5376 KB |
ok, correct split |
5 |
Correct |
8 ms |
5504 KB |
ok, correct split |
6 |
Correct |
7 ms |
5376 KB |
ok, correct split |
7 |
Correct |
9 ms |
5504 KB |
ok, correct split |
8 |
Correct |
8 ms |
5376 KB |
ok, correct split |
9 |
Correct |
10 ms |
5888 KB |
ok, correct split |
10 |
Correct |
10 ms |
5760 KB |
ok, correct split |
11 |
Correct |
8 ms |
5504 KB |
ok, correct split |
12 |
Correct |
12 ms |
5888 KB |
ok, correct split |
13 |
Correct |
8 ms |
5376 KB |
ok, correct split |
14 |
Correct |
7 ms |
5376 KB |
ok, correct split |
15 |
Correct |
8 ms |
5376 KB |
ok, correct split |
16 |
Correct |
8 ms |
5376 KB |
ok, correct split |
17 |
Correct |
8 ms |
5376 KB |
ok, correct split |
18 |
Correct |
8 ms |
5376 KB |
ok, correct split |
19 |
Correct |
8 ms |
5504 KB |
ok, correct split |
20 |
Correct |
10 ms |
5760 KB |
ok, correct split |
21 |
Correct |
10 ms |
5760 KB |
ok, correct split |
22 |
Correct |
10 ms |
5760 KB |
ok, correct split |
23 |
Correct |
9 ms |
5888 KB |
ok, correct split |
24 |
Correct |
10 ms |
5888 KB |
ok, correct split |
25 |
Correct |
10 ms |
5760 KB |
ok, correct split |
26 |
Incorrect |
261 ms |
5880 KB |
jury found a solution, contestant did not |
27 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
4992 KB |
ok, correct split |
2 |
Correct |
7 ms |
4992 KB |
ok, correct split |
3 |
Correct |
7 ms |
4992 KB |
ok, correct split |
4 |
Correct |
7 ms |
4992 KB |
ok, correct split |
5 |
Correct |
7 ms |
4992 KB |
ok, correct split |
6 |
Correct |
7 ms |
5120 KB |
ok, correct split |
7 |
Correct |
190 ms |
27620 KB |
ok, correct split |
8 |
Correct |
152 ms |
18168 KB |
ok, correct split |
9 |
Correct |
174 ms |
28256 KB |
ok, correct split |
10 |
Correct |
134 ms |
14424 KB |
ok, correct split |
11 |
Correct |
115 ms |
14448 KB |
ok, correct split |
12 |
Correct |
9 ms |
4992 KB |
ok, correct split |
13 |
Correct |
7 ms |
4992 KB |
ok, correct split |
14 |
Correct |
8 ms |
5120 KB |
ok, correct split |
15 |
Correct |
98 ms |
14456 KB |
ok, correct split |
16 |
Correct |
107 ms |
15736 KB |
ok, correct split |
17 |
Correct |
94 ms |
14192 KB |
ok, correct split |
18 |
Correct |
118 ms |
15608 KB |
ok, correct split |
19 |
Correct |
145 ms |
17272 KB |
ok, correct split |
20 |
Correct |
112 ms |
15352 KB |
ok, correct split |
21 |
Correct |
101 ms |
16624 KB |
ok, correct split |
22 |
Correct |
93 ms |
16624 KB |
ok, correct split |
23 |
Correct |
116 ms |
16732 KB |
ok, correct split |
24 |
Correct |
8 ms |
5376 KB |
ok, correct split |
25 |
Correct |
142 ms |
17408 KB |
ok, correct split |
26 |
Correct |
45 ms |
9336 KB |
ok, correct split |
27 |
Correct |
8 ms |
5504 KB |
ok, correct split |
28 |
Correct |
166 ms |
20344 KB |
ok, correct split |
29 |
Correct |
226 ms |
20088 KB |
ok, correct split |
30 |
Correct |
161 ms |
20856 KB |
ok, correct split |
31 |
Correct |
206 ms |
21240 KB |
ok, correct split |
32 |
Correct |
166 ms |
20604 KB |
ok, correct split |
33 |
Correct |
32 ms |
8696 KB |
ok, no valid answer |
34 |
Correct |
55 ms |
10232 KB |
ok, no valid answer |
35 |
Correct |
88 ms |
15092 KB |
ok, no valid answer |
36 |
Correct |
157 ms |
14840 KB |
ok, no valid answer |
37 |
Correct |
80 ms |
15472 KB |
ok, no valid answer |
38 |
Correct |
7 ms |
5504 KB |
ok, correct split |
39 |
Correct |
8 ms |
5376 KB |
ok, no valid answer |
40 |
Correct |
8 ms |
4992 KB |
ok, correct split |
41 |
Correct |
8 ms |
5376 KB |
ok, correct split |
42 |
Correct |
8 ms |
5504 KB |
ok, correct split |
43 |
Correct |
7 ms |
5376 KB |
ok, correct split |
44 |
Correct |
9 ms |
5504 KB |
ok, correct split |
45 |
Correct |
8 ms |
5376 KB |
ok, correct split |
46 |
Correct |
10 ms |
5888 KB |
ok, correct split |
47 |
Correct |
10 ms |
5760 KB |
ok, correct split |
48 |
Correct |
8 ms |
5504 KB |
ok, correct split |
49 |
Correct |
12 ms |
5888 KB |
ok, correct split |
50 |
Correct |
8 ms |
5376 KB |
ok, correct split |
51 |
Correct |
7 ms |
5376 KB |
ok, correct split |
52 |
Correct |
8 ms |
5376 KB |
ok, correct split |
53 |
Correct |
8 ms |
5376 KB |
ok, correct split |
54 |
Correct |
8 ms |
5376 KB |
ok, correct split |
55 |
Correct |
8 ms |
5376 KB |
ok, correct split |
56 |
Correct |
8 ms |
5504 KB |
ok, correct split |
57 |
Correct |
10 ms |
5760 KB |
ok, correct split |
58 |
Correct |
10 ms |
5760 KB |
ok, correct split |
59 |
Correct |
10 ms |
5760 KB |
ok, correct split |
60 |
Correct |
9 ms |
5888 KB |
ok, correct split |
61 |
Correct |
10 ms |
5888 KB |
ok, correct split |
62 |
Correct |
10 ms |
5760 KB |
ok, correct split |
63 |
Incorrect |
261 ms |
5880 KB |
jury found a solution, contestant did not |
64 |
Halted |
0 ms |
0 KB |
- |