Submission #253394

# Submission time Handle Problem Language Result Execution time Memory
253394 2020-07-27T22:16:26 Z eohomegrownapps Friend (IOI14_friend) C++14
46 / 100
35 ms 1528 KB
#include "friend.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// Find out best sample
vector<vector<int>> adjlist;
int subtask1(int n,int confidence[],int host[],int protocol[]){
    adjlist.resize(n);
    for (int i = 1; i<n; i++){
        if (protocol[i]==0){
            adjlist[host[i]].push_back(i);
            adjlist[i].push_back(host[i]);
        } else if (protocol[i]==1){
            for (int x : adjlist[host[i]]){
                adjlist[i].push_back(x);
                adjlist[x].push_back(i);
            }
        } else {
            for (int x : adjlist[host[i]]){
                adjlist[i].push_back(x);
                adjlist[x].push_back(i);
            };
            adjlist[host[i]].push_back(i);
            adjlist[i].push_back(host[i]);
        }
    }
    ll mx = 0;
    for (int i = 0; i<(1<<n); i++){
        //check if ok
        bool works = true;
        ll tot = 0;
        for (int j = 0; j<n; j++){
            if ((1<<j)&i){
                tot+=confidence[j];
                for (int k : adjlist[j]){
                    if ((1<<k)&i){
                        works=false;
                        break;
                    }
                }
            }
            if (works==false){
                break;
            }
        }
        if (works==false){
            continue;
        }
        mx=max(mx,tot);
    }
    return mx;
}
 
int subtask2(int n,int confidence[],int host[],int protocol[]){
    int tot = 0;
    for (int i = 0; i<n; i++){
        tot+=confidence[i];
    }
    return tot;
}
 
int subtask3(int n,int confidence[],int host[],int protocol[]){
    int mx = 0;
    for (int i = 0; i<n; i++){
        mx=max(mx,confidence[i]);
    }
    return mx;
}
 
vector<vector<int>> dp;
int *conf;
 
int f(int node, int par, bool use){
    if (dp[node][use]!=-1){
        return dp[node][use];
    }
    if (use){
        int tot = conf[node];
        for (int i : adjlist[node]){
            if (i==par){continue;}
            tot+=f(i,node,false);
        }
        return dp[node][use]=tot;
    } else {
        int tot = 0;
        for (int i : adjlist[node]){
            if (i==par){continue;}
            tot+=max(f(i,node,true),f(i,node,false));
        }
        return dp[node][use]=tot;
    }
}
 
int subtask4(int n,int confidence[],int host[],int protocol[]){
    adjlist.resize(n);
    conf = confidence;
    for (int i = 1; i<n; i++){
        adjlist[i].push_back(host[i]);
        adjlist[host[i]].push_back(i);
    }
    dp.resize(n,vector<int>(2,-1));
    return max(f(0,-1,false),f(0,-1,true));
}

vector<int> lhs;
vector<int> dist;
vector<int> rmatch;
vector<bool> visited;

void bfs(int node){
    queue<int> q;
    q.push(node);
    dist[node]=0;
    lhs.push_back(node);
    while (q.size()>0){
        int f= q.front();
        q.pop();
        for (int i : adjlist[f]){
            if (dist[i]!=2){continue;}
            dist[i]=!dist[f];
            if (dist[i]==0){
                lhs.push_back(i);
            }
            q.push(i);
        }
    }
}

bool augmentingPath(int node){
    if (visited[node]){
        return false;
    }
    visited[node]=true;
    for (int i : adjlist[node]){
        if (rmatch[i]==-1||augmentingPath(rmatch[i])){
            rmatch[i]=node;
            return true;
        }
    }
    return false;
}

int subtask5(int n,int confidence[],int host[],int protocol[]){
    adjlist.resize(n);
    for (int i = 1; i<n; i++){
        if (protocol[i]==0){
            adjlist[host[i]].push_back(i);
            adjlist[i].push_back(host[i]);
        } else if (protocol[i]==1){
            for (int x : adjlist[host[i]]){
                adjlist[i].push_back(x);
                adjlist[x].push_back(i);
            }
        } else {
            for (int x : adjlist[host[i]]){
                adjlist[i].push_back(x);
                adjlist[x].push_back(i);
            };
            adjlist[host[i]].push_back(i);
            adjlist[i].push_back(host[i]);
        }
    }
    dist.resize(n,2);
    for (int i = 0; i<n; i++){
        if (dist[i]!=2){continue;}
        bfs(i);
    }
    int length = 0;
    rmatch.resize(n,-1);
    for (int i : lhs){
        if (rmatch[i]!=-1){continue;}
        visited.assign(n,false);
        length+=augmentingPath(i);
    }
    return length;
}
 
int subtask6(int n,int confidence[],int host[],int protocol[]){
    return 0;
}
 
int findSample(int n,int confidence[],int host[],int protocol[]){
    if (n<=10){
        return subtask1(n,confidence,host,protocol); 
    } else {
        bool protocols[3]={0,0,0};
        for (int i = 1; i<n; i++){
            protocols[protocol[i]]=true;
        }
        //cout<<protocols[0]<<' '<<protocols[1]<<' '<<protocols[2]<<'\n';
        if (protocols[0]==0&&protocols[1]==1&&protocols[2]==0){
            return subtask2(n,confidence,host,protocol); 
        } else if (protocols[0]==0&&protocols[1]==0&&protocols[2]==1){
            return subtask3(n,confidence,host,protocol); 
        } else if (protocols[0]==1&&protocols[1]==0&&protocols[2]==0){
            return subtask4(n,confidence,host,protocol); 
        } else if (protocols[0]==1&&protocols[1]==1&&protocols[2]==0){
            return subtask5(n,confidence,host,protocol); 
        } else {
            return subtask6(n,confidence,host,protocol); 
        }
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 512 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Incorrect 1 ms 384 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Incorrect 35 ms 1528 KB Output isn't correct
13 Halted 0 ms 0 KB -