Submission #313475

#TimeUsernameProblemLanguageResultExecution timeMemory
313475talant117408Friend (IOI14_friend)C++17
16 / 100
13 ms6784 KiB
#include "friend.h"
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef pair <ll, ll> pii;
 
#define precision(n) fixed << setprecision(n)
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define mp make_pair
#define eps (double)1e-9
#define PI 2*acos(0.0)
#define endl "\n"
#define sz(v) (int)(v).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define do_not_disturb ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

const int N = 1e5+7;
int adj[11][11];
vector <vector <int>> graph(N);

int findSample(int n, int conf[], int host[], int prot[]){
	
    int cnt = 0, cnt1 = 0, cnt2 = 0;
    
    for(int i = 1; i < n; i++){
        if(!prot[i]){
            cnt++;
            graph[host[i]].pb(i);
            graph[i].pb(host[i]);
        }
        else if(prot[i]&1){
            cnt1++;
            for(auto to : graph[host[i]]){
                graph[to].pb(i);
                graph[i].pb(to);
            }
        }
        else{
            cnt2++;
            for(auto to : graph[host[i]]){
                graph[to].pb(i);
                graph[i].pb(to);
            }
            graph[host[i]].pb(i);
            graph[i].pb(host[i]);
        }
    }
    
    if(n <= 10){
        vector <int> pere(n);
        iota(all(pere), 0);
        int mx = 0;
        do{
            int sum = conf[pere[0]], prev = pere[0];
            for(int i = 1; i < n; i++){
                int flag = 0;
                for(auto to : graph[prev]){
                    if(to == pere[i]){
                        flag ++;
                        break;
                    }
                }
                if(!flag){
                    sum += conf[pere[1]];
                    prev = pere[1];
                }
            }
            mx = max(mx, sum);
        }
        while(next_permutation(all(pere)));
        return mx;
    }
    else if(cnt1 == n-1){
        int sum = 0;
        for(int i = 0; i < n; i++){
            sum += conf[i];
        }
        return sum;
    }
    else if(cnt2 == n-1){
        int mx = 0;
        for(int i = 0; i < n; i++){
            mx = max(mx, conf[i]);
        }
        return mx;
    }
    
    return 1;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...