Submission #584805

#TimeUsernameProblemLanguageResultExecution timeMemory
584805jack715친구 (IOI14_friend)C++14
0 / 100
2 ms1108 KiB
#include "friend.h"
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define pp pop_back
#define mp make_pair
#define bb back
#define ff first
#define ss second

using namespace std;

// Find out best sample
int findSample(int n,int confidence[],int host[],int protocol[]){
	vector<vector<int> > path(n);
	for (int i = 1; i < n; i++) {
		if (protocol[i] == 0) {
			path[i].pb(host[i]);
			path[host[i]].pb(i);
		} else if (protocol[i] == 1) {
			for (int con : path[host[i]]) {
				path[i].pb(con);
				path[con].pb(i);
			}
		} else {
			for (int con : path[host[i]]) {
				path[i].pb(con);
				path[con].pb(i);
			}
			path[i].pb(host[i]);
			path[host[i]].pb(i);
		}
	}

	int ans = 0, now;
	queue<pair<int, int> > q;
    vector<bool> used(n);
    q.push({0, 1});
    now = 0;
    for (int i = 0; i < n; i++) used[i] = 0;
    used[0] = 1;
    while (!q.empty()) {
        int indx = q.front().ff, state = q.front().ss;
        q.pop();
        if (state) now += confidence[indx];
        for (int next : path[indx]) {
            if (used[next]) continue;
            used[next] = 1;
            q.push({next, 1-state});
        }
    }
    ans = max(ans, now);

    q.push({0, 0});
	now = 0;
    for (int i = 0; i < n; i++) used[i] = 0;
    used[0] = 1;
    while (!q.empty()) {
        int indx = q.front().ff, state = q.front().ss;
        q.pop();
        if (state) now += confidence[indx];
        for (int next : path[indx]) {
            if (used[next]) continue;
            used[next] = 1;
            q.push({next, 1-state});
        }
    }
    ans = max(ans, now);

    return ans;
}
#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...