# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
874069 | Sandarach151 | Friend (IOI14_friend) | C++17 | 118 ms | 65536 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
int findSample(int n, int confidence[], int host[], int protocol[]){
if(n<=10){
set<int> adg[n];
for(int i=1; i<n; i++){
if(protocol[i]==0){
adg[host[i]].insert(i);
adg[i].insert(host[i]);
}
else if(protocol[i]==1){
for(auto u : adg[host[i]]){
adg[i].insert(u);
adg[u].insert(i);
}
}
else{
for(auto u : adg[host[i]]){
adg[i].insert(u);
adg[u].insert(i);
}
adg[host[i]].insert(i);
adg[i].insert(host[i]);
}
}
int maxx = 0;
for(int mask=0; mask < (1<<n); mask++){
bool test = true;
int cur = 0;
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
if(((mask & (1<<i))!=0) && ((mask & (1<<j))!=0) && adg[i].count(j)){
test = false;
break;
}
}
if(!test){
break;
}
}
if(test){
for(int i=0; i<n; i++){
if((mask & (1<<i))!=0){
cur+=confidence[i];
}
}
maxx = max(maxx, cur);
}
}
return maxx;
}
else{
bool res0 = true;
bool res1 = true;
bool res2 = true;
for(int i=1; i<n; i++){
if(protocol[i]==0){
res1 = false;
res2 = false;
}
if(protocol[i]==1){
res0 = false;
res2 = false;
}
if(protocol[i]==2){
res0 = false;
res1 = false;
}
}
if(res1){
int ans = 0;
for(int i=0; i<n; i++){
ans += confidence[i];
}
return ans;
}
else if(res2){
int ans = 0;
for(int i=0; i<n; i++){
ans = max(ans, confidence[i]);
}
return ans;
}
else if(res0){
vector<int> adg[n];
for(int i=1; i<n; i++){
if(protocol[i]==0){
adg[host[i]].push_back(i);
adg[i].push_back(host[i]);
}
else if(protocol[i]==1){
for(auto u : adg[host[i]]){
adg[i].push_back(u);
adg[u].push_back(i);
}
}
else{
for(auto u : adg[host[i]]){
adg[i].push_back(u);
adg[u].push_back(i);
}
adg[host[i]].push_back(i);
adg[i].push_back(host[i]);
}
}
vector<int> color(n, -1);
queue<int> que;
que.push(0);
color[0]=0;
while(!que.empty()){
int cur = que.front();
que.pop();
for(auto u : adg[cur]){
if(color[u]==-1){
color[u]=1-color[cur];
que.push(u);
}
}
}
int tot0 = 0;
int tot1 = 0;
for(int i=0; i<n; i++){
if(color[i]==0) tot0+=confidence[i];
else tot1+=confidence[i];
}
return max(tot0, tot1);
}
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |