# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
58629 |
2018-07-18T14:04:44 Z |
ngkan146 |
Friend (IOI14_friend) |
C++11 |
|
6 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);
G[i].push_back(host[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;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2680 KB |
Output is correct |
2 |
Correct |
4 ms |
2792 KB |
Output is correct |
3 |
Correct |
5 ms |
2792 KB |
Output is correct |
4 |
Correct |
5 ms |
2892 KB |
Output is correct |
5 |
Correct |
6 ms |
2968 KB |
Output is correct |
6 |
Correct |
5 ms |
2968 KB |
Output is correct |
7 |
Correct |
5 ms |
2968 KB |
Output is correct |
8 |
Incorrect |
4 ms |
3024 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
3024 KB |
Output is correct |
2 |
Correct |
5 ms |
3024 KB |
Output is correct |
3 |
Correct |
6 ms |
3024 KB |
Output is correct |
4 |
Correct |
6 ms |
3024 KB |
Output is correct |
5 |
Correct |
5 ms |
3024 KB |
Output is correct |
6 |
Correct |
5 ms |
3024 KB |
Output is correct |
7 |
Correct |
6 ms |
3024 KB |
Output is correct |
8 |
Correct |
6 ms |
3048 KB |
Output is correct |
9 |
Correct |
4 ms |
3048 KB |
Output is correct |
10 |
Correct |
5 ms |
3052 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
3052 KB |
Output is correct |
2 |
Correct |
5 ms |
3052 KB |
Output is correct |
3 |
Correct |
5 ms |
3052 KB |
Output is correct |
4 |
Correct |
2 ms |
3052 KB |
Output is correct |
5 |
Correct |
6 ms |
3052 KB |
Output is correct |
6 |
Correct |
4 ms |
3052 KB |
Output is correct |
7 |
Correct |
5 ms |
3052 KB |
Output is correct |
8 |
Correct |
6 ms |
3052 KB |
Output is correct |
9 |
Correct |
5 ms |
3052 KB |
Output is correct |
10 |
Correct |
5 ms |
3068 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
5 ms |
3068 KB |
Output is correct |
5 |
Correct |
5 ms |
3068 KB |
Output is correct |
6 |
Incorrect |
5 ms |
3068 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
3068 KB |
Output is correct |
2 |
Correct |
3 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 |
4 ms |
3068 KB |
Output is correct |
6 |
Correct |
5 ms |
3068 KB |
Output is correct |
7 |
Correct |
4 ms |
3068 KB |
Output is correct |
8 |
Correct |
4 ms |
3068 KB |
Output is correct |
9 |
Correct |
6 ms |
3068 KB |
Output is correct |
10 |
Correct |
5 ms |
3068 KB |
Output is correct |
11 |
Incorrect |
5 ms |
3068 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
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 |
5 ms |
3068 KB |
Output is correct |
5 |
Correct |
4 ms |
3068 KB |
Output is correct |
6 |
Correct |
6 ms |
3068 KB |
Output is correct |
7 |
Incorrect |
5 ms |
3068 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |