Submission #144237

# Submission time Handle Problem Language Result Execution time Memory
144237 2019-08-16T11:20:12 Z TadijaSebez Split the Attractions (IOI19_split) C++14
40 / 100
1070 ms 1048580 KB
#include "split.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
const int N=100050;
int n,fir,sec,fm,sm;
vector<int> G[N],E[N];
void AddEdge(int u, int v){ G[u].pb(v);G[v].pb(u);}
int ans[N],sz[N],par[N];
bool was[N];
bool ok;
int ver,col;
void Tree(int u)
{
	sz[u]=1;
	was[u]=1;
	for(int v:G[u]) if(!was[v])
	{
		Tree(v);
		sz[u]+=sz[v];
		E[u].pb(v);
		par[v]=u;
	}
	if(sz[u]>=fir && n-sz[u]>=sec){ ok=1;ver=u;col=1;}
	if(sz[u]>=sec && n-sz[u]>=fir){ ok=1;ver=u;col=2;}
}
int Cen(int u){ for(int v:E[u]) if(sz[v]*2>n) return Cen(v);return u;}
int rem,mark;
void DFS(int u)
{
	if(rem>0) rem--,ans[u]=mark;
	for(int v:E[u]) if(v!=ver) DFS(v);
}
void Fill(){ for(int i=1;i<=n;i++) if(!ans[i]) ans[i]=fm^sm;}
vector<int> Answer(){ vector<int> ret;for(int i=1;i<=n;i++) ret.pb(ans[i]);return ret;}
int cnt,comp[N],csz[N];
vector<int> C[N];
void COMP(int u, int p, int c){ comp[u]=c;csz[c]++;for(int v:E[u]) if(v!=p) COMP(v,u,c);}
bool used[N],solved,can_use[N];
int node_cnt;
void Try(int u)
{
	used[u]=1;
	if(!solved)
	{
		node_cnt+=csz[u];
		can_use[u]=1;
		if(node_cnt>=fir) solved=1;
	}
	for(int v:C[u]) if(!used[v]) Try(v);
}
void DFS1(int u)
{
	if(fir>0)
	{
		ans[u]=fm;
		fir--;
	}
	for(int v:G[u]) if(can_use[comp[v]] && !ans[v]) DFS1(v);
}
void DFS2(int u)
{
	if(sec>0)
	{
		ans[u]=sm;
		sec--;
	}
	for(int v:G[u]) if(!ans[v]) DFS2(u);
}
vector<int> Solve()
{
	Tree(1);
	if(ok)
	{
		rem=col==1?fir:sec;
		mark=col==1?fm:sm;
		DFS(ver);
		rem=col==1?sec:fir;
		mark=col==1?sm:fm;
		DFS(1);
		Fill();
		return Answer();
	}
	int cen=Cen(1);
	for(int i=2;i<=n;i++) E[i].pb(par[i]);
	for(int v:E[cen]) COMP(v,cen,++cnt);
	for(int u=1;u<=n;u++) for(int v:G[u]) if(u!=cen && v!=cen) C[comp[u]].pb(comp[v]),C[comp[v]].pb(comp[u]);
	int start=-1;
	for(int i=1;i<=cnt;i++) if(!used[i])
	{
		node_cnt=0;
		Try(i);
		if(solved){ start=i;break;}
	}
	if(!solved) return vector<int>(n,0);
	for(int i=1;i<=n;i++) if(comp[i]==start){ DFS1(i);break;}
	DFS2(cen);
	Fill();
	return Answer();
}
vector<int> find_split(int _n, int a, int b, int c, vector<int> p, vector<int> q)
{
	n=_n;
	vector<pair<int,int>> v={{a,1},{b,2},{c,3}};
	sort(v.begin(),v.end());
	tie(fir,fm)=v[0];
	tie(sec,sm)=v[1];
	for(int i=0;i<p.size();i++) AddEdge(p[i]+1,q[i]+1);
	return Solve();
}

Compilation message

split.cpp: In function 'std::vector<int> find_split(int, int, int, int, std::vector<int>, std::vector<int>)':
split.cpp:108:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<p.size();i++) AddEdge(p[i]+1,q[i]+1);
              ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 13 ms 7416 KB ok, correct split
2 Correct 9 ms 7416 KB ok, correct split
3 Correct 9 ms 7416 KB ok, correct split
4 Correct 9 ms 7388 KB ok, correct split
5 Correct 9 ms 7420 KB ok, correct split
6 Correct 9 ms 7420 KB ok, correct split
7 Correct 138 ms 24692 KB ok, correct split
8 Correct 131 ms 22484 KB ok, correct split
9 Correct 133 ms 21624 KB ok, correct split
10 Correct 138 ms 25076 KB ok, correct split
11 Correct 131 ms 24948 KB ok, correct split
# Verdict Execution time Memory Grader output
1 Correct 9 ms 7416 KB ok, correct split
2 Correct 8 ms 7288 KB ok, correct split
3 Correct 9 ms 7416 KB ok, correct split
4 Correct 161 ms 20976 KB ok, correct split
5 Correct 111 ms 15736 KB ok, correct split
6 Correct 149 ms 24976 KB ok, correct split
7 Correct 152 ms 22132 KB ok, correct split
8 Correct 162 ms 18424 KB ok, correct split
9 Correct 124 ms 17268 KB ok, correct split
10 Correct 73 ms 14964 KB ok, correct split
11 Correct 77 ms 14896 KB ok, correct split
12 Correct 77 ms 14832 KB ok, correct split
# Verdict Execution time Memory Grader output
1 Correct 8 ms 7416 KB ok, correct split
2 Correct 110 ms 15740 KB ok, correct split
3 Correct 42 ms 10872 KB ok, correct split
4 Correct 9 ms 7416 KB ok, correct split
5 Correct 167 ms 19732 KB ok, correct split
6 Correct 125 ms 19444 KB ok, correct split
7 Correct 125 ms 19316 KB ok, correct split
8 Correct 126 ms 20596 KB ok, correct split
9 Correct 133 ms 19132 KB ok, correct split
10 Correct 44 ms 11508 KB ok, no valid answer
11 Correct 64 ms 13492 KB ok, no valid answer
12 Correct 104 ms 18552 KB ok, no valid answer
13 Correct 134 ms 19004 KB ok, no valid answer
14 Correct 83 ms 18260 KB ok, no valid answer
# Verdict Execution time Memory Grader output
1 Correct 8 ms 7416 KB ok, correct split
2 Correct 9 ms 7416 KB ok, no valid answer
3 Correct 8 ms 7416 KB ok, correct split
4 Correct 8 ms 7416 KB ok, correct split
5 Correct 8 ms 7416 KB ok, correct split
6 Correct 8 ms 7416 KB ok, correct split
7 Correct 8 ms 7416 KB ok, correct split
8 Correct 8 ms 7416 KB ok, correct split
9 Correct 16 ms 7672 KB ok, correct split
10 Correct 11 ms 7672 KB ok, correct split
11 Correct 8 ms 7416 KB ok, correct split
12 Correct 11 ms 7672 KB ok, correct split
13 Correct 8 ms 7416 KB ok, correct split
14 Correct 8 ms 7416 KB ok, correct split
15 Correct 9 ms 7388 KB ok, correct split
16 Correct 8 ms 7416 KB ok, correct split
17 Correct 8 ms 7416 KB ok, correct split
18 Correct 8 ms 7416 KB ok, correct split
19 Correct 10 ms 7544 KB ok, correct split
20 Correct 9 ms 7544 KB ok, correct split
21 Correct 16 ms 7672 KB ok, correct split
22 Correct 12 ms 7672 KB ok, correct split
23 Correct 14 ms 7800 KB ok, correct split
24 Correct 9 ms 7676 KB ok, correct split
25 Correct 12 ms 7672 KB ok, correct split
26 Runtime error 1070 ms 1048580 KB Execution killed with signal 9 (could be triggered by violating memory limits)
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 7416 KB ok, correct split
2 Correct 9 ms 7416 KB ok, correct split
3 Correct 9 ms 7416 KB ok, correct split
4 Correct 9 ms 7388 KB ok, correct split
5 Correct 9 ms 7420 KB ok, correct split
6 Correct 9 ms 7420 KB ok, correct split
7 Correct 138 ms 24692 KB ok, correct split
8 Correct 131 ms 22484 KB ok, correct split
9 Correct 133 ms 21624 KB ok, correct split
10 Correct 138 ms 25076 KB ok, correct split
11 Correct 131 ms 24948 KB ok, correct split
12 Correct 9 ms 7416 KB ok, correct split
13 Correct 8 ms 7288 KB ok, correct split
14 Correct 9 ms 7416 KB ok, correct split
15 Correct 161 ms 20976 KB ok, correct split
16 Correct 111 ms 15736 KB ok, correct split
17 Correct 149 ms 24976 KB ok, correct split
18 Correct 152 ms 22132 KB ok, correct split
19 Correct 162 ms 18424 KB ok, correct split
20 Correct 124 ms 17268 KB ok, correct split
21 Correct 73 ms 14964 KB ok, correct split
22 Correct 77 ms 14896 KB ok, correct split
23 Correct 77 ms 14832 KB ok, correct split
24 Correct 8 ms 7416 KB ok, correct split
25 Correct 110 ms 15740 KB ok, correct split
26 Correct 42 ms 10872 KB ok, correct split
27 Correct 9 ms 7416 KB ok, correct split
28 Correct 167 ms 19732 KB ok, correct split
29 Correct 125 ms 19444 KB ok, correct split
30 Correct 125 ms 19316 KB ok, correct split
31 Correct 126 ms 20596 KB ok, correct split
32 Correct 133 ms 19132 KB ok, correct split
33 Correct 44 ms 11508 KB ok, no valid answer
34 Correct 64 ms 13492 KB ok, no valid answer
35 Correct 104 ms 18552 KB ok, no valid answer
36 Correct 134 ms 19004 KB ok, no valid answer
37 Correct 83 ms 18260 KB ok, no valid answer
38 Correct 8 ms 7416 KB ok, correct split
39 Correct 9 ms 7416 KB ok, no valid answer
40 Correct 8 ms 7416 KB ok, correct split
41 Correct 8 ms 7416 KB ok, correct split
42 Correct 8 ms 7416 KB ok, correct split
43 Correct 8 ms 7416 KB ok, correct split
44 Correct 8 ms 7416 KB ok, correct split
45 Correct 8 ms 7416 KB ok, correct split
46 Correct 16 ms 7672 KB ok, correct split
47 Correct 11 ms 7672 KB ok, correct split
48 Correct 8 ms 7416 KB ok, correct split
49 Correct 11 ms 7672 KB ok, correct split
50 Correct 8 ms 7416 KB ok, correct split
51 Correct 8 ms 7416 KB ok, correct split
52 Correct 9 ms 7388 KB ok, correct split
53 Correct 8 ms 7416 KB ok, correct split
54 Correct 8 ms 7416 KB ok, correct split
55 Correct 8 ms 7416 KB ok, correct split
56 Correct 10 ms 7544 KB ok, correct split
57 Correct 9 ms 7544 KB ok, correct split
58 Correct 16 ms 7672 KB ok, correct split
59 Correct 12 ms 7672 KB ok, correct split
60 Correct 14 ms 7800 KB ok, correct split
61 Correct 9 ms 7676 KB ok, correct split
62 Correct 12 ms 7672 KB ok, correct split
63 Runtime error 1070 ms 1048580 KB Execution killed with signal 9 (could be triggered by violating memory limits)
64 Halted 0 ms 0 KB -