제출 #438262

#제출 시각아이디문제언어결과실행 시간메모리
438262bobbilyking친구 (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[1]==n-1){ ans = sum; } else if (prot[2]==n-1){ ans = mx; } else if (prot[3] == 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) 메시지

friend.cpp: In function 'int findSample(ll, ll*, ll*, ll*)':
friend.cpp:39:17: warning: array subscript 3 is above array bounds of 'int [3]' [-Warray-bounds]
   39 |  else if (prot[3] == n-1){
      |           ~~~~~~^
friend.cpp:22:6: note: while referencing 'prot'
   22 |  int prot[3];
      |      ^~~~
/usr/bin/ld: /tmp/cc4MXYng.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccSm0Tah.o:friend.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/cc4MXYng.o: in function `main':
grader.cpp:(.text.startup+0xdd): undefined reference to `findSample(int, int*, int*, int*)'
collect2: error: ld returned 1 exit status