제출 #438264

#제출 시각아이디문제언어결과실행 시간메모리
438264bobbilykingFriend (IOI14_friend)C++17
컴파일 에러
0 ms0 KiB
#include "friend.h"
#include<bits/stdc++.h>
using namespace std;

#define N 100010
typedef long long int ll;
ll cost[N], bip[N];
vector<ll> adj[N];

void dfs(int i, int p, int t){
	if (bip[i]!=-1) return;
	bip[i] = t;
	for (int x: adj[i]){
		if (x==p) continue;
		dfs(x,i,(t+1)&1);
	}
}

int findSample(ll n, ll  c[], ll h[], ll p[]){
	int sum = 0;
	ll mx = 0;
	int prot[3];
	for (int i=  0  ; i < 3; i++)  prot[i]  =  0;
	for (int i = 0 ; i< n; i++) {
		cost[i] = c[i];
		sum  +=  c[i];
		mx = max(mx,c[i]);
	}
	for (int i =1; i < n; i++){
		prot[p[i]]++;
	}
	int ans = 0;
	if (prot[0]==n-1){
		ans  =  sum;
	}
	else if (prot[1]==n-1){
		ans  =  mx;
	}
	else if (prot[2] == n-1){
		for (int i = 1;  i <  n;  i++){
			adj[i].push_back(h[i]);
			adj[h[i]].push_back(i);
		}
		for (int i = 0 ;  i <  n; i+=1) bip[i]  = -1;
		dfs(0,0,0);
		int s2  = 0;
		for (int i = 0; i < n; i+=1) if (bip[i] ==1)s2+=c[i];
		ans = max(s2,sum-s2);
	}
	return ans;
}

void readInput(){
	ll n; cin>>n;
	ll c[n], h[n], p[n];
	for (int i = 0; i < n; i++) cin>>c[i];
	for (int i =0 ; i < n; i++)  cin>>h[i];
	for  (int i =0; i < n; i++) cin>>p[i];
	cout<<findSample(n,c,h,p)<<'\n';
}

int main(){
	//readInput();
}

컴파일 시 표준 에러 (stderr) 메시지

/usr/bin/ld: /tmp/ccftSbvt.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccHzUKDu.o:friend.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccftSbvt.o: in function `main':
grader.cpp:(.text.startup+0xdd): undefined reference to `findSample(int, int*, int*, int*)'
collect2: error: ld returned 1 exit status