#include "split.h"
#include <iostream>
#include <algorithm>
using namespace std;
const int nmax=100005;
vector<int> res;
vector<int> ad[nmax],v[nmax];
pair<int,int> C[3];
int viz[nmax],q[nmax],w[nmax],tt[nmax];
int i,n;
void sterge(int A,int B)
{
for(int it=0;it<2;it++)
{
for(int i=0;i<v[A].size();i++)
if(v[A][i]==B)
{
swap(v[A][i],v[A].back());
v[A].pop_back();
}
swap(A,B);
}
}
void et(int x,int cate,int col)
{
int p,u;
for(i=0;i<n;i++)
viz[i]=0;
viz[x]=1;
q[u=1]=x;
for(p=1;p<=u;p++)
{
x=q[p];
for(int i=0;i<v[x].size();i++)
if(!viz[v[x][i]])
{
q[++u]=v[x][i];
viz[v[x][i]]=1;
}
}
for(i=1;i<=cate;i++)
res[q[i]]=col;
}
bool gasit;
void solve(int x)
{
w[x]=1;
for(int i=0;i<v[x].size();i++)
if((!w[v[x][i]]))
{
tt[v[x][i]]=x;
solve(v[x][i]);
w[x]+=w[v[x][i]];
}
if(!gasit)
{
if(w[x]>=C[0].first&&n-w[x]>=C[1].first)
{
sterge(x,tt[x]);
et(x,C[0].first,C[0].second);
et(tt[x],C[1].first,C[1].second);
gasit=1;
}
else
{
if(w[x]>=C[1].first&&n-w[x]>=C[0].first)
{
sterge(x,tt[x]);
et(x,C[1].first,C[1].second);
et(tt[x],C[0].first,C[0].second);
gasit=1;
}
}
}
}
void dfs(int x)
{
for(int i=0;i<ad[x].size();i++)
if(tt[ad[x][i]]==-1)
{
tt[ad[x][i]]=x;
dfs(ad[x][i]);
}
}
void get_spanning(int x)
{
for(i=0;i<n;i++)
tt[i]=-1;
tt[x]=x;
dfs(x);
for(i=0;i<n;i++)
v[i].clear();
for(i=0;i<n;i++)
if(tt[i]!=i)
{
v[tt[i]].push_back(i);
v[i].push_back(tt[i]);
}
solve(0);
}
vector<int> find_split(int nn, int a, int b, int c, vector<int> p, vector<int> q) {
n=nn;
for(i=0;i<p.size();i++)
{
ad[p[i]].push_back(q[i]);
ad[q[i]].push_back(p[i]);
}
res.resize(n);
for(i=0;i<n;i++)
res[i]=0;
pair<int,int> v[3];
C[0]={a,1};
C[1]={b,2};
C[2]={c,3};
sort(C,C+3);
get_spanning(0);
if(gasit)
{
int oth=(C[0].second^C[1].second);
for(i=0; i<n; i++)
if(!res[i])
res[i]=oth;
}
return res;
}
Compilation message
split.cpp: In function 'void sterge(int, int)':
split.cpp:15:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<v[A].size();i++)
~^~~~~~~~~~~~
split.cpp: In function 'void et(int, int, int)':
split.cpp:34:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<v[x].size();i++)
~^~~~~~~~~~~~
split.cpp: In function 'void solve(int)':
split.cpp:48:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<v[x].size();i++)
~^~~~~~~~~~~~
split.cpp: In function 'void dfs(int)':
split.cpp:78:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<ad[x].size();i++)
~^~~~~~~~~~~~~
split.cpp: In function 'std::vector<int> find_split(int, int, int, int, std::vector<int>, std::vector<int>)':
split.cpp:103:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(i=0;i<p.size();i++)
~^~~~~~~~~
split.cpp:111:19: warning: unused variable 'v' [-Wunused-variable]
pair<int,int> v[3];
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
4988 KB |
ok, correct split |
2 |
Correct |
6 ms |
4984 KB |
ok, correct split |
3 |
Correct |
6 ms |
4984 KB |
ok, correct split |
4 |
Correct |
6 ms |
4984 KB |
ok, correct split |
5 |
Correct |
6 ms |
5112 KB |
ok, correct split |
6 |
Correct |
6 ms |
5112 KB |
ok, correct split |
7 |
Correct |
154 ms |
19576 KB |
ok, correct split |
8 |
Correct |
152 ms |
18296 KB |
ok, correct split |
9 |
Correct |
148 ms |
18004 KB |
ok, correct split |
10 |
Correct |
156 ms |
19832 KB |
ok, correct split |
11 |
Correct |
171 ms |
19764 KB |
ok, correct split |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
4988 KB |
ok, correct split |
2 |
Correct |
7 ms |
4984 KB |
ok, correct split |
3 |
Correct |
6 ms |
4984 KB |
ok, correct split |
4 |
Correct |
160 ms |
18384 KB |
ok, correct split |
5 |
Correct |
122 ms |
15480 KB |
ok, correct split |
6 |
Correct |
146 ms |
19860 KB |
ok, correct split |
7 |
Correct |
143 ms |
18260 KB |
ok, correct split |
8 |
Correct |
174 ms |
16888 KB |
ok, correct split |
9 |
Correct |
126 ms |
15436 KB |
ok, correct split |
10 |
Correct |
82 ms |
15984 KB |
ok, correct split |
11 |
Correct |
78 ms |
15988 KB |
ok, correct split |
12 |
Correct |
83 ms |
15984 KB |
ok, correct split |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
4984 KB |
ok, correct split |
2 |
Correct |
126 ms |
15480 KB |
ok, correct split |
3 |
Correct |
47 ms |
9212 KB |
ok, correct split |
4 |
Correct |
6 ms |
4984 KB |
ok, correct split |
5 |
Correct |
136 ms |
16820 KB |
ok, correct split |
6 |
Correct |
170 ms |
16644 KB |
ok, correct split |
7 |
Correct |
141 ms |
16408 KB |
ok, correct split |
8 |
Correct |
154 ms |
17332 KB |
ok, correct split |
9 |
Correct |
139 ms |
16376 KB |
ok, correct split |
10 |
Correct |
39 ms |
8276 KB |
ok, no valid answer |
11 |
Correct |
55 ms |
9848 KB |
ok, no valid answer |
12 |
Correct |
95 ms |
14964 KB |
ok, no valid answer |
13 |
Correct |
127 ms |
14712 KB |
ok, no valid answer |
14 |
Correct |
81 ms |
15216 KB |
ok, no valid answer |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
4984 KB |
ok, correct split |
2 |
Correct |
6 ms |
4984 KB |
ok, no valid answer |
3 |
Correct |
6 ms |
4984 KB |
ok, correct split |
4 |
Correct |
6 ms |
4984 KB |
ok, correct split |
5 |
Correct |
6 ms |
4984 KB |
ok, correct split |
6 |
Correct |
6 ms |
5112 KB |
ok, correct split |
7 |
Correct |
6 ms |
4984 KB |
ok, correct split |
8 |
Correct |
6 ms |
4984 KB |
ok, correct split |
9 |
Correct |
9 ms |
5368 KB |
ok, correct split |
10 |
Correct |
9 ms |
5368 KB |
ok, correct split |
11 |
Correct |
6 ms |
4984 KB |
ok, correct split |
12 |
Correct |
9 ms |
5368 KB |
ok, correct split |
13 |
Correct |
6 ms |
4984 KB |
ok, correct split |
14 |
Correct |
6 ms |
4984 KB |
ok, correct split |
15 |
Correct |
6 ms |
4856 KB |
ok, correct split |
16 |
Correct |
6 ms |
4984 KB |
ok, correct split |
17 |
Correct |
6 ms |
4984 KB |
ok, correct split |
18 |
Correct |
11 ms |
5112 KB |
ok, correct split |
19 |
Correct |
6 ms |
5112 KB |
ok, correct split |
20 |
Correct |
7 ms |
5112 KB |
ok, correct split |
21 |
Correct |
8 ms |
5320 KB |
ok, correct split |
22 |
Correct |
8 ms |
5372 KB |
ok, correct split |
23 |
Correct |
9 ms |
5372 KB |
ok, correct split |
24 |
Correct |
8 ms |
5240 KB |
ok, correct split |
25 |
Correct |
11 ms |
5340 KB |
ok, correct split |
26 |
Incorrect |
8 ms |
5372 KB |
jury found a solution, contestant did not |
27 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
4988 KB |
ok, correct split |
2 |
Correct |
6 ms |
4984 KB |
ok, correct split |
3 |
Correct |
6 ms |
4984 KB |
ok, correct split |
4 |
Correct |
6 ms |
4984 KB |
ok, correct split |
5 |
Correct |
6 ms |
5112 KB |
ok, correct split |
6 |
Correct |
6 ms |
5112 KB |
ok, correct split |
7 |
Correct |
154 ms |
19576 KB |
ok, correct split |
8 |
Correct |
152 ms |
18296 KB |
ok, correct split |
9 |
Correct |
148 ms |
18004 KB |
ok, correct split |
10 |
Correct |
156 ms |
19832 KB |
ok, correct split |
11 |
Correct |
171 ms |
19764 KB |
ok, correct split |
12 |
Correct |
6 ms |
4988 KB |
ok, correct split |
13 |
Correct |
7 ms |
4984 KB |
ok, correct split |
14 |
Correct |
6 ms |
4984 KB |
ok, correct split |
15 |
Correct |
160 ms |
18384 KB |
ok, correct split |
16 |
Correct |
122 ms |
15480 KB |
ok, correct split |
17 |
Correct |
146 ms |
19860 KB |
ok, correct split |
18 |
Correct |
143 ms |
18260 KB |
ok, correct split |
19 |
Correct |
174 ms |
16888 KB |
ok, correct split |
20 |
Correct |
126 ms |
15436 KB |
ok, correct split |
21 |
Correct |
82 ms |
15984 KB |
ok, correct split |
22 |
Correct |
78 ms |
15988 KB |
ok, correct split |
23 |
Correct |
83 ms |
15984 KB |
ok, correct split |
24 |
Correct |
6 ms |
4984 KB |
ok, correct split |
25 |
Correct |
126 ms |
15480 KB |
ok, correct split |
26 |
Correct |
47 ms |
9212 KB |
ok, correct split |
27 |
Correct |
6 ms |
4984 KB |
ok, correct split |
28 |
Correct |
136 ms |
16820 KB |
ok, correct split |
29 |
Correct |
170 ms |
16644 KB |
ok, correct split |
30 |
Correct |
141 ms |
16408 KB |
ok, correct split |
31 |
Correct |
154 ms |
17332 KB |
ok, correct split |
32 |
Correct |
139 ms |
16376 KB |
ok, correct split |
33 |
Correct |
39 ms |
8276 KB |
ok, no valid answer |
34 |
Correct |
55 ms |
9848 KB |
ok, no valid answer |
35 |
Correct |
95 ms |
14964 KB |
ok, no valid answer |
36 |
Correct |
127 ms |
14712 KB |
ok, no valid answer |
37 |
Correct |
81 ms |
15216 KB |
ok, no valid answer |
38 |
Correct |
6 ms |
4984 KB |
ok, correct split |
39 |
Correct |
6 ms |
4984 KB |
ok, no valid answer |
40 |
Correct |
6 ms |
4984 KB |
ok, correct split |
41 |
Correct |
6 ms |
4984 KB |
ok, correct split |
42 |
Correct |
6 ms |
4984 KB |
ok, correct split |
43 |
Correct |
6 ms |
5112 KB |
ok, correct split |
44 |
Correct |
6 ms |
4984 KB |
ok, correct split |
45 |
Correct |
6 ms |
4984 KB |
ok, correct split |
46 |
Correct |
9 ms |
5368 KB |
ok, correct split |
47 |
Correct |
9 ms |
5368 KB |
ok, correct split |
48 |
Correct |
6 ms |
4984 KB |
ok, correct split |
49 |
Correct |
9 ms |
5368 KB |
ok, correct split |
50 |
Correct |
6 ms |
4984 KB |
ok, correct split |
51 |
Correct |
6 ms |
4984 KB |
ok, correct split |
52 |
Correct |
6 ms |
4856 KB |
ok, correct split |
53 |
Correct |
6 ms |
4984 KB |
ok, correct split |
54 |
Correct |
6 ms |
4984 KB |
ok, correct split |
55 |
Correct |
11 ms |
5112 KB |
ok, correct split |
56 |
Correct |
6 ms |
5112 KB |
ok, correct split |
57 |
Correct |
7 ms |
5112 KB |
ok, correct split |
58 |
Correct |
8 ms |
5320 KB |
ok, correct split |
59 |
Correct |
8 ms |
5372 KB |
ok, correct split |
60 |
Correct |
9 ms |
5372 KB |
ok, correct split |
61 |
Correct |
8 ms |
5240 KB |
ok, correct split |
62 |
Correct |
11 ms |
5340 KB |
ok, correct split |
63 |
Incorrect |
8 ms |
5372 KB |
jury found a solution, contestant did not |
64 |
Halted |
0 ms |
0 KB |
- |