제출 #943353

#제출 시각아이디문제언어결과실행 시간메모리
943353THXuan경주 (Race) (IOI11_race)C++14
컴파일 에러
0 ms0 KiB
#include <iostream> #include <vector> #include <algorithm> #include <cstring> #include <queue> #include <set> #include <map> #define INF 1e9 using namespace std; typedef long long ll; int n, k; ll ans = INF; vector<pair<int, int>>adj[200005]; bool visited[200005]; ll dp[200005], cnt[1000005]; vector<ll>v; int get_size(int s, int e) { dp[s] = 1; for (auto u : adj[s]) { if (u.first == e || visited[u.first]) continue; get_size(u.first, s); dp[s] += dp[u.first]; } return dp[s]; } int get_centroid(int s, int e, int n) { for (auto u : adj[s]) { if (u.first == e || visited[u.first]) continue; if (dp[u.first] * 2 > n)return get_centroid(u.first, s, n); } return s; } void dfs(int s, int e, bool flag, int sum, ll dep = 1) { if (sum > k) return; if (!flag) { ans = min(ans, dep + cnt[k - sum]); } else { cnt[sum] = min(cnt[sum], dep); v.push_back(sum); } for (auto u : adj[s]) { if (u.first == e || visited[u.first]) continue; dfs(u.first, s, flag, sum + u.second, dep + 1); } } void centroid_decomposition(int node) { int centroid = get_centroid(node, 0, get_size(node, 0)); visited[centroid] = true; for (auto u : adj[centroid]) { if (!visited[u.first]) { dfs(u.first, centroid, false, u.second); dfs(u.first, centroid, true, u.second); } } for (auto u : v) cnt[u] = INF; v.clear(); for (auto u : adj[centroid]) { if (!visited[u.first])centroid_decomposition(u.first); } } int best_path(int a, int b, int h[][2], int l[]) { n = a; k = b; for (int i = 1; i <= n - 1; i++) { int u = h[i][0], v = h[i][1], w = l[i]; adj[u].push_back({ v, w }); adj[v].push_back({ u, w }); } for (int i = 1; i <= 1000005; i++)cnt[i] = INF; centroid_decomposition(1); if (ans == INF) return -1; else return ans; } int h[200005][2], l[200005]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> k; for (int i = 1; i <= n - 1; i++) { cin >> h[i][0] >> h[i][1]; cin >> l[i]; } cout << best_path(n, k, h, l) << "\n"; }

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

race.cpp: In function 'int best_path(int, int, int (*)[2], int*)':
race.cpp:75:43: warning: iteration 1000004 invokes undefined behavior [-Waggressive-loop-optimizations]
   75 |  for (int i = 1; i <= 1000005; i++)cnt[i] = INF;
      |                                           ^
race.cpp:75:20: note: within this loop
   75 |  for (int i = 1; i <= 1000005; i++)cnt[i] = INF;
      |                  ~~^~~~~~~~~~
/usr/bin/ld: /tmp/cciNd3xq.o: in function `main':
race.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccMpltcp.o:grader.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status