Submission #152070

# Submission time Handle Problem Language Result Execution time Memory
152070 2019-09-06T08:11:28 Z oolimry Split the Attractions (IOI19_split) C++14
0 / 100
122 ms 14356 KB
#include <bits/stdc++.h>

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> ii;
vi adj[100005];
int dp[100005];
bool vis[100005];
void dfs(int u){
	vis[u] = true;
	for(int i = 0;i < adj[u].size();i++){
		int v = adj[u][i];
		if(!vis[v]){
			dfs(v);
			dp[u] += dp[v];
		}
	}
	dp[u] += 1;
}
vi find_split(int n, int aaa, int bbb, int ccc, vi p, vi q) {
	for(int i = 0;i < p.size();i++){
		int x = p[i];
		int y = q[i];
		adj[x].push_back(y);
		adj[y].push_back(x);
	}
	
	dfs(0);
	
	vector<pair<int,int> > vv;
	vv.push_back(ii(aaa,1));
	vv.push_back(ii(bbb,2));
	vv.push_back(ii(ccc,3));
	sort(vv.begin(),vv.end());
	int a = vv[0].first;
	int b = vv[1].first;
	for(int i = 0;i < p.size();i++){
		int x = p[i];
		int y = q[i];
		
		int ll = min(dp[x],dp[y]);
		int rr = dp[0] - ll;
		
		int l = min(ll,rr);
		int r = max(ll,rr);
		if(l >= a && r >= b){
			queue<int> bfs;
			
			vi vis;
			for(int i = 0;i < n;i++) vis.push_back(vv[2].second);
			//vis[x] = vv[0].second;
			//vis[y] = vv[1].second;

			bfs.push(x);
			
			int cnt = a;
			while(!bfs.empty()){
				int u = bfs.front();
				bfs.pop();
				
				if(vis[u] != vv[2].second) continue;
				vis[u] = vv[0].second;
				cnt--;
				if(cnt == 0) break;
				for(int j = 0;j < adj[u].size();j++){
					int v = adj[u][j];
					if(v == x || v == y) continue;
					bfs.push(v);
				}
			}
			
			while(!bfs.empty()) bfs.pop();
			bfs.push(y);
			
			cnt = b;
			while(!bfs.empty()){
				int u = bfs.front();
				bfs.pop();
				
				if(vis[u] != vv[2].second) continue;
				vis[u] = vv[1].second;
				cnt--;
				if(cnt == 0) break;
				for(int j = 0;j < adj[u].size();j++){
					int v = adj[u][j];
					if(v == x || v == y) continue;
					bfs.push(v);
				}
			}
			return vis;
		}
	}
	vi none;
	for(int i = 0;i < n;i++) none.push_back(0);
	return none;
}

Compilation message

split.cpp: In function 'void dfs(int)':
split.cpp:12:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0;i < adj[u].size();i++){
                ~~^~~~~~~~~~~~~~~
split.cpp: In function 'vi find_split(int, int, int, int, vi, vi)':
split.cpp:22:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0;i < p.size();i++){
                ~~^~~~~~~~~~
split.cpp:38:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0;i < p.size();i++){
                ~~^~~~~~~~~~
split.cpp:66:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int j = 0;j < adj[u].size();j++){
                   ~~^~~~~~~~~~~~~~~
split.cpp:85:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int j = 0;j < adj[u].size();j++){
                   ~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2808 KB ok, correct split
2 Correct 4 ms 2680 KB ok, correct split
3 Correct 4 ms 2680 KB ok, correct split
4 Correct 4 ms 2680 KB ok, correct split
5 Correct 4 ms 2680 KB ok, correct split
6 Correct 4 ms 2680 KB ok, correct split
7 Correct 97 ms 14200 KB ok, correct split
8 Correct 89 ms 12788 KB ok, correct split
9 Incorrect 88 ms 12276 KB invalid split: #1=21895, #2=78103, #3=2
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2680 KB ok, correct split
2 Correct 4 ms 2680 KB ok, correct split
3 Correct 4 ms 2680 KB ok, correct split
4 Correct 113 ms 13552 KB ok, correct split
5 Correct 83 ms 9820 KB ok, correct split
6 Correct 94 ms 14356 KB ok, correct split
7 Correct 96 ms 12632 KB ok, correct split
8 Correct 122 ms 13296 KB ok, correct split
9 Correct 86 ms 9728 KB ok, correct split
10 Correct 64 ms 9960 KB ok, correct split
11 Incorrect 63 ms 9844 KB invalid split: #1=1, #2=1, #3=99997
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 2680 KB invalid split: #1=1, #2=1, #3=3
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2680 KB ok, correct split
2 Correct 4 ms 2720 KB ok, no valid answer
3 Correct 4 ms 2680 KB ok, correct split
4 Incorrect 4 ms 2680 KB invalid split: #1=3, #2=3, #3=5
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2808 KB ok, correct split
2 Correct 4 ms 2680 KB ok, correct split
3 Correct 4 ms 2680 KB ok, correct split
4 Correct 4 ms 2680 KB ok, correct split
5 Correct 4 ms 2680 KB ok, correct split
6 Correct 4 ms 2680 KB ok, correct split
7 Correct 97 ms 14200 KB ok, correct split
8 Correct 89 ms 12788 KB ok, correct split
9 Incorrect 88 ms 12276 KB invalid split: #1=21895, #2=78103, #3=2
10 Halted 0 ms 0 KB -