#include <bits/stdc++.h>
#include "split.h"
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MAXN = 1123456;
const ll N = 2e5;
vector <int> v[N];
int t[N], P[N];
bool f[N];
void dfs(int x, int pr){
if(t[x])return;
P[x] = pr;
t[x] = 1;
for(auto to : v[x])if(to != pr){
dfs(to, x);
t[x] += t[to];
}
}
vector<int> find_split(int n, int a, int b, int c, vector<int> p, vector<int> q) {
int m = p.size(), mx = 0;
for(int i = 0; i < m; i++){
v[p[i]].push_back(q[i]);
v[q[i]].push_back(p[i]);
mx = max(mx, (int)v[p[i]].size());
mx = max(mx, (int)v[q[i]].size());
}
vector <int> res(n);
if(a == 1){
queue <int> q;
int start = 0;
q.push(start);
vector <bool> f(n);
f[start] = 1;
while(!q.empty()){
int x = q.front();
q.pop();
if(!b)break;
b--;
res[x] = 2;
for(auto to : v[x])if(!f[to]){
f[to] = 1;
q.push(to);
}
}
for(int i = 0; i < n; i++)if(res[i] == 0){res[i] = 1; break;}
for(int i = 0; i < n; i++)if(res[i] == 0)res[i] = 3;
return res;
}else{
int start = 0;
for(int i = 0; i < n; i++)if(v[i].size() == 1)start = i;
vector <int> cnt(3);
cnt[0] = a;
cnt[1] = b;
cnt[2] = c;
vector <int> p(3);
p[0] = 1;
p[1] = 2;
p[2] = 3;
for(int i = 0; i < 3; i++)
for(int j = i + 1; j < 3; j++)if(cnt[p[i] - 1] > cnt[p[j] - 1])swap(p[i], p[j]);
dfs(start, start);
for(int i = 0; i < n; i++)if(t[i] >= cnt[p[0] - 1] && n - t[i] >= cnt[p[1] - 1]){
queue <int> q;
f[i] = 1;
f[P[i]] = 1;
res[P[i]] = p[0];
cnt[p[0] - 1]--;
q.push(P[i]);
while(!q.empty()){
int x = q.front();
q.pop();
res[x] = p[0];
for(auto to : v[x])if(!f[to] && cnt[p[0] - 1]){
cnt[p[0] - 1]--;
f[to] = 1;
q.push(to);
}
}
res[i] = p[1];
cnt[p[1] - 1]--;
q.push(i);
while(!q.empty()){
int x = q.front();
q.pop();
res[x] = p[1];
for(auto to : v[x])if(!f[to] && cnt[p[1] - 1]){
cnt[p[1] - 1]--;
f[to] = 1;
q.push(to);
}
}
for(auto &j : res)if(j == 0)j = p[2];
return res;
}
return res;
}
return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
4984 KB |
ok, correct split |
2 |
Correct |
6 ms |
4984 KB |
ok, correct split |
3 |
Correct |
7 ms |
5112 KB |
ok, correct split |
4 |
Correct |
7 ms |
4984 KB |
ok, correct split |
5 |
Correct |
4 ms |
4984 KB |
ok, correct split |
6 |
Correct |
7 ms |
4984 KB |
ok, correct split |
7 |
Correct |
118 ms |
18480 KB |
ok, correct split |
8 |
Correct |
124 ms |
11256 KB |
ok, correct split |
9 |
Incorrect |
117 ms |
18424 KB |
invalid split: #1=57251, #2=42747, #3=2 |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
4984 KB |
ok, correct split |
2 |
Correct |
6 ms |
4984 KB |
ok, correct split |
3 |
Correct |
6 ms |
4984 KB |
ok, correct split |
4 |
Correct |
106 ms |
11440 KB |
ok, correct split |
5 |
Correct |
80 ms |
10232 KB |
ok, correct split |
6 |
Correct |
75 ms |
10104 KB |
ok, correct split |
7 |
Correct |
83 ms |
10104 KB |
ok, correct split |
8 |
Correct |
119 ms |
12664 KB |
ok, correct split |
9 |
Correct |
96 ms |
10332 KB |
ok, correct split |
10 |
Correct |
66 ms |
10992 KB |
ok, correct split |
11 |
Correct |
67 ms |
10868 KB |
ok, correct split |
12 |
Correct |
71 ms |
10992 KB |
ok, correct split |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
4988 KB |
ok, correct split |
2 |
Incorrect |
85 ms |
11256 KB |
invalid split: #1=20000, #2=21840, #3=58160 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
4984 KB |
ok, correct split |
2 |
Correct |
7 ms |
4956 KB |
ok, no valid answer |
3 |
Correct |
6 ms |
5052 KB |
ok, correct split |
4 |
Incorrect |
7 ms |
4984 KB |
invalid split: #1=2, #2=3, #3=6 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
4984 KB |
ok, correct split |
2 |
Correct |
6 ms |
4984 KB |
ok, correct split |
3 |
Correct |
7 ms |
5112 KB |
ok, correct split |
4 |
Correct |
7 ms |
4984 KB |
ok, correct split |
5 |
Correct |
4 ms |
4984 KB |
ok, correct split |
6 |
Correct |
7 ms |
4984 KB |
ok, correct split |
7 |
Correct |
118 ms |
18480 KB |
ok, correct split |
8 |
Correct |
124 ms |
11256 KB |
ok, correct split |
9 |
Incorrect |
117 ms |
18424 KB |
invalid split: #1=57251, #2=42747, #3=2 |
10 |
Halted |
0 ms |
0 KB |
- |