제출 #416437

#제출 시각아이디문제언어결과실행 시간메모리
416437mjhmjh1104친구 (IOI14_friend)C++17
컴파일 에러
0 ms0 KiB
#include "friend.h" #include <algorithm> using namespace std; int uf[1006]; int _find(int x) { if (uf[x] == -1) return x; return uf[x] = _find(uf[x]); } void _merge(int x, int y) { x = _find(x), y = _find(y); if (x != y) uf[x] = y, mx[y] = max(mx[y], mx[x]); } int findSample(int n, int confidence[], int host[], int protocol[]) { if (protocol[1] == 1) { int res = 0; for (int i = 0; i < n; i++) res += confidence[i]; return res; } else if (protocol[1] == 2) { int res = 0; for (int i = 0; i < n; i++) res = max(res, confidence[i]); return res; } else { int res = 0; for (int i = 0; i < n; i++) uf[i] = -1, mx[i] = confidence[i]; for (int i = 1; i < n; i++) _merge(host[i], i); for (int i = 0; i < n; i++) if (uf[i] == -1) res += mx[i]; return res; } }

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

friend.cpp: In function 'void _merge(int, int)':
friend.cpp:14:25: error: 'mx' was not declared in this scope; did you mean 'x'?
   14 |  if (x != y) uf[x] = y, mx[y] = max(mx[y], mx[x]);
      |                         ^~
      |                         x
friend.cpp: In function 'int findSample(int, int*, int*, int*)':
friend.cpp:28:43: error: 'mx' was not declared in this scope
   28 |   for (int i = 0; i < n; i++) uf[i] = -1, mx[i] = confidence[i];
      |                                           ^~
friend.cpp:30:55: error: 'mx' was not declared in this scope
   30 |   for (int i = 0; i < n; i++) if (uf[i] == -1) res += mx[i];
      |                                                       ^~