제출 #976089

#제출 시각아이디문제언어결과실행 시간메모리
976089Amaarsaa경주 (Race) (IOI11_race)C++14
컴파일 에러
0 ms0 KiB
#include "race.h" #include<bits/stdc++.h> using namespace std; #define MAX_N 500000 vector < pair < int, int > > adj[200004]; int sz[200004], used[200005] = {0}, d[1000004]; int N, K; int H[MAX_N][2]; int L[MAX_N]; vector < int > v; int find_size(int node, int parent) { sz[node] = 1; for ( pair <int,int >& A : adj[node]) { int child = A.first; if ( used[child] || parent == child) continue; sz[node] += find_size(child, node); } return sz[node]; } int find_centroid(int node, int parent, int n) { for ( pair <int, int>& A : adj[node]) { int child = A.first; if ( child == parent || used[child] ) continue; if ( sz[child] * 2 > n) return find_centroid(child, node, n); } return node; } int ans = -1; void dfs(int node, int parent, int budjaagaa, int dist, int depth) { if ( dist > K) return; if ( budjaagaa) { if ( d[dist] == -1) d[dist] = depth; else d[dist] = min(d[dist], depth); v.push_back(dist); } else { if ( d[K - dist] != -1) { if ( ans == -1) ans = depth + d[K - dist]; else ans = min(ans, depth + d[K - dist]); } } for ( pair < int, int>&A : adj[node]) { int child = A.first; if ( used[child] || child == parent) continue; dfs(child, node, budjaagaa, dist + A.second, depth + 1); } } int solve(int node) { int c = find_centroid(node, node, find_size(node, node)); used[c] = 1; v.clear(); for ( pair <int, int>& A : adj[c]) { int child = A.first; if ( used[child]) continue; dfs(child, c, 0, A.second, 1); dfs(child, c, 1, A.second, 1); } for (int X : v) { d[X] = -1; } for ( pair <int, int>& A : adj[c]) { int child = A.first; if ( used[child]) continue; solve(child); } } int best_path(int N, int K, int H[][2], int L[]){ for (int i = 0; i < (N - 1); i ++) { adj[H[i][0]].push_back({H[i][1], L[i]}); adj[H[i][1]].push_back({H[i][0], L[i]}); } for (int i = 0; i <=K; i ++) d[i] = -1; solve(0); return ans; } void read_input() { int i; cin >> N >> K; for (i = 0; i < N - 1; i ++) cin >> H[i][0] >> H[i][1] >> L[i]; } int main() { int ans; read_input(); ans = best_path(N,K,H,L); cout << ans << endl; return 0; }

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

race.cpp: In function 'int solve(int)':
race.cpp:68:1: warning: no return statement in function returning non-void [-Wreturn-type]
   68 | }
      | ^
/usr/bin/ld: /tmp/cciDByIT.o: in function `read_input()':
race.cpp:(.text+0x170): multiple definition of `read_input()'; /tmp/ccVK6vFX.o:grader.cpp:(.text+0x0): first defined here
/usr/bin/ld: /tmp/cciDByIT.o: in function `main':
race.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccVK6vFX.o:grader.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status