답안 #122105

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
122105 2019-06-27T14:41:56 Z brcode 친구 (IOI14_friend) C++14
컴파일 오류
0 ms 0 KB
#include <iostream>
#include <vector>
#include <set>
#include "friend.h"
using namespace std;
const int MAXN = 1e6+5;
bool visited[MAXN];
bool visited2[MAXN];
int val[MAXN];
vector<int> v1[MAXN];
int first;

set<int> s1;
int dp[MAXN][6];
void dfs(int curr,int par){
    visited[curr] = true;
 
    for(int x:v1[curr]){
        if(x!=par && !visited[x]){
            dfs(x,curr);
        }else if(x!=par && visited[x]){
            first = x;
        }
    }
}
void dfs2(int curr){
    dp[curr][1] = val[curr];
    visited2[curr] = true;
    if(s1.find(curr)==s1.end()){
        dp[curr][3] = val[curr];
    }
    for(int x:v1[curr]){
        
        if(!visited2[x] && x!=first){
            dfs2(x);
            dp[curr][1]+=dp[x][0];
            dp[curr][0]+=max(dp[x][0],dp[x][1]);
            dp[curr][3]+=dp[x][4];
            dp[curr][4]+=max(dp[x][3],dp[x][4]);
        }
    }
    
}
int findSample(int n, int confidence[], int host[], int protocol[]){
    bool one = true;
    bool two = true;
    bool three = true;
    for(int i=1;i<n;i++){
        if(protocol[i]!=0){
            one = false;
        }
        if(protocol[i]!=1){
            two = false;
        }
        if(protocol[i]!=2){
            three = false;
        }
    }
    if(two){
        int ans = 0;
        for(int i=1;i<n;i++){
            ans+=confidence[i];
        }
        return ans;
    }
    if(three){
        int ans = 0;
        for(int i=1;i<n;i++){
            ans = max(ans,confidence[i]);
        }
        return ans;
    }
    if(one){
        int ans = 0;
        for(int i=1;i<n;i++){
            v1[host[i]].push_back(i);
            v1[i].push_back(host[i]);
        }
        for(int i=1;i<n;i++){
            val[i] = confidence[i];
        }
        for(long long i=1;i<=n;i++){
            if(!visited[i]){
                
                first = i;
                dfs(i,i);
                long long temp1 = 0;
                long long temp2 = val[first];
                for(int x:v1[first]){
                       s1.insert(x);
                }
                for(long long x:v1[first]){
                    if(!visited2[x]){
                        
                        dfs2(x);
                        temp1+=max(dp[x][0],dp[x][1]);
                        temp2+=dp[x][4];
                        //cout<<temp2<<endl;
                    }
                }
                ans+=max(temp1,temp2);
            }
        }
        return ans;
    }
}
int main(){
    
}

Compilation message

friend.cpp: In function 'int findSample(int, int*, int*, int*)':
friend.cpp:106:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
/tmp/ccBbJ5It.o: In function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/cc0n77yV.o:friend.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status