답안 #58627

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
58627 2018-07-18T14:01:27 Z ngkan146 친구 (IOI14_friend) C++11
16 / 100
7 ms 3068 KB
#include "friend.h"
#include <bits/stdc++.h>
using namespace std;

#define IAmYourFriend 0
#define MyFriendsAreYourFriends 1
#define WeAreYourFriends 2

#define WHITE 0
#define BLACK 1

int dsup[100000];
int dsu_p(int x){
	return x == dsup[x] ? x : dsup[x] = dsu_p(dsup[x]);
}
void dsu_union(int x,int y){
	dsup[dsu_p(y)] = dsu_p(x);
}

int val[100000], color[100000];
vector <int> G[100000];
vector <int> lst[2];
bool visited[100000];

void dfs(int u){
	visited[u] = 1;
	lst[color[u]].push_back(u);
	if (val[dsu_p(u)] < val[u])
		swap(val[dsu_p(u)], val[u]);
	for(auto v: G[u]){
		if (!visited[v])
			dfs(v);
	}
}
int findSample(int n,int a[],int host[],int type[]){
	for(int i=0;i<n;i++)
		dsup[i] = i,
		val[i] = a[i];
		
	//~ color[0] = WHITE;
	for(int i=1;i<n;i++){
		G[host[i]].push_back(i);
		if (type[i] == IAmYourFriend){
			color[i] = color[host[i]] ^ 1;
		}
		else if (type[i] == MyFriendsAreYourFriends){
			color[i] = color[host[i]];
		}
		else{
			color[i] = color[host[i]];
			dsu_union(i, host[i]);
		}
	}
	
	int answer = 0;
	for(int i=0;i<n;i++){
		if (visited[i])	continue;
		lst[0].clear();
		lst[1].clear();
		dfs(i);
		int res[2] = {0,0};
		for(auto v: lst[0]){
			if (dsu_p(v) == v)	res[0] += val[v];
		}
		for(auto v: lst[1]){
			if (dsu_p(v) == v)	res[1] += val[v];
		}
		answer += max(res[0], res[1]);
	}
	return answer;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2680 KB Output is correct
2 Correct 2 ms 2872 KB Output is correct
3 Correct 4 ms 2872 KB Output is correct
4 Correct 4 ms 2872 KB Output is correct
5 Correct 4 ms 2872 KB Output is correct
6 Correct 6 ms 2872 KB Output is correct
7 Correct 5 ms 2992 KB Output is correct
8 Incorrect 4 ms 2992 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2992 KB Output is correct
2 Correct 4 ms 2992 KB Output is correct
3 Correct 4 ms 2992 KB Output is correct
4 Correct 6 ms 2992 KB Output is correct
5 Correct 5 ms 2992 KB Output is correct
6 Correct 5 ms 2992 KB Output is correct
7 Correct 6 ms 2992 KB Output is correct
8 Correct 5 ms 2992 KB Output is correct
9 Correct 5 ms 3004 KB Output is correct
10 Correct 6 ms 3024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 3024 KB Output is correct
2 Correct 6 ms 3024 KB Output is correct
3 Correct 6 ms 3024 KB Output is correct
4 Correct 5 ms 3024 KB Output is correct
5 Correct 3 ms 3024 KB Output is correct
6 Correct 5 ms 3024 KB Output is correct
7 Correct 4 ms 3024 KB Output is correct
8 Correct 5 ms 3024 KB Output is correct
9 Correct 4 ms 3024 KB Output is correct
10 Correct 5 ms 3024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 3068 KB Output is correct
2 Correct 4 ms 3068 KB Output is correct
3 Correct 4 ms 3068 KB Output is correct
4 Correct 4 ms 3068 KB Output is correct
5 Correct 5 ms 3068 KB Output is correct
6 Incorrect 4 ms 3068 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 3068 KB Output is correct
2 Correct 4 ms 3068 KB Output is correct
3 Correct 4 ms 3068 KB Output is correct
4 Correct 4 ms 3068 KB Output is correct
5 Correct 5 ms 3068 KB Output is correct
6 Correct 4 ms 3068 KB Output is correct
7 Correct 5 ms 3068 KB Output is correct
8 Correct 5 ms 3068 KB Output is correct
9 Correct 7 ms 3068 KB Output is correct
10 Correct 6 ms 3068 KB Output is correct
11 Incorrect 6 ms 3068 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 3068 KB Output is correct
2 Correct 4 ms 3068 KB Output is correct
3 Correct 7 ms 3068 KB Output is correct
4 Correct 5 ms 3068 KB Output is correct
5 Correct 5 ms 3068 KB Output is correct
6 Correct 5 ms 3068 KB Output is correct
7 Incorrect 4 ms 3068 KB Output isn't correct
8 Halted 0 ms 0 KB -