제출 #1184287

#제출 시각아이디문제언어결과실행 시간메모리
1184287pensive친구 (IOI14_friend)C++20
8 / 100
1095 ms5216 KiB
#include "friend.h"
#include <iostream>
#include <algorithm>
#include <vector>
#include <algorithm>

using namespace std;
#define ll long long
#define REP(a,i,n) for (int i=a;i<n;i++)
#define f first
#define s second

void iayf(int n, int i, int host, vector<vector<int>> &adjList) {
    adjList[host].push_back(i);
    adjList[i].push_back(host);
}
void mfayf(int n, int i, int host, vector<vector<int>> &adjList) {
    for (auto j : adjList[host]) {
        adjList[j].push_back(i);
        adjList[i].push_back(j);
    }
}
void wayf(int n, int i, int host, vector<vector<int>> &adjList) {
    mfayf(n,i,host,adjList);
    iayf(n, i, host, adjList);
}
int maxSample(int n, int i, vector<vector<int>> &adjList, vector<bool> includes, int confidence[]) {
    if (i==n) {
        return 0;
    }
    int cleared = adjList[i].size();
    for (auto j : adjList[i]) {
        if (includes[j]==0) {
            cleared--;
        }
    }
    int ans= maxSample(n,i+1,adjList,includes,confidence);
    if (cleared) return ans;
    includes[i]=1;
    return max(ans, confidence[i]+maxSample(n,i+1,adjList,includes,confidence));
}

int findSample(int n, int confidence[], int host[], int protocol[]) {
    vector<vector<int> > adjList(n);
    REP(1,i,n) {
        if (protocol[i]==0) iayf(n,i,host[i],adjList);
        else if (protocol[i]==1) mfayf(n,i,host[i],adjList);
        else if (protocol[i]==2) wayf(n,i,host[i],adjList);
    }
    vector<bool> includes(n);
    return maxSample(n,1,adjList,includes,confidence);
} 
#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...