제출 #957799

#제출 시각아이디문제언어결과실행 시간메모리
957799Trisanu_Das경주 (Race) (IOI11_race)C++17
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> #include "race.h" using namespace std; #define ff first #define ss second vector<pair<int, int> > adj[200005]; map<int, int> sum_to_dist[200005]; int sum[200005], dist[200005], N, K, ans; void dfs(int u, int p, int s, int d){ sum_to_dist[u][s] = d; sum[u] = s; dist[u] = d; for(int v : adj[u]) if(v.ff != p) dfs(v.ff, u, s + v.ss, d + 1); } void merge_dfs(int u, int p){ int target = k + 2 * sum[u]; for(auto v : adj[u]){ if(v.ff == p) continue; merge_dfs(v.ff, u); if(sum_to_dist[v.ff].size() > sum_to_dist[u].size()) swap(sum_to_dist[v.ff], sum_to_dist[u]); for(auto p : sum_to_dist[v.ff]) if(sum_to_dist[u].find(target - p.ff) != sum_to_dist[u].end()) ans = min(ans, sum_to_dist[u][target - p.ff] + p.ss - 2 * dist[u]); for(auto p : sum_to_dist[v.ff]){ if(sum_to_dist[u].find(p.ff) == sum_to_dist[u].end()) sum_to_dist[u].insert(p); else sum_to_dist[u][p.ff] = min(sum_to_dist[u][p.ff], p.ss); } } } int best_path(int n, int k, int h[][2], int l[]){ N = n; K = k; for(int i = 0; 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}); } dfs(0, -1, 0, 0); merge_dfs(0, -1); return ans == INT_MAX ? -1 : ans; }

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

race.cpp: In function 'void dfs(int, int, int, int)':
race.cpp:15:20: error: cannot convert 'std::pair<int, int>' to 'int' in initialization
   15 |   for(int v : adj[u]) if(v.ff != p) dfs(v.ff, u, s + v.ss, d + 1);
      |                    ^
race.cpp:4:12: error: request for member 'first' in 'v', which is of non-class type 'int'
    4 | #define ff first
      |            ^~~~~
race.cpp:15:28: note: in expansion of macro 'ff'
   15 |   for(int v : adj[u]) if(v.ff != p) dfs(v.ff, u, s + v.ss, d + 1);
      |                            ^~
race.cpp:4:12: error: request for member 'first' in 'v', which is of non-class type 'int'
    4 | #define ff first
      |            ^~~~~
race.cpp:15:43: note: in expansion of macro 'ff'
   15 |   for(int v : adj[u]) if(v.ff != p) dfs(v.ff, u, s + v.ss, d + 1);
      |                                           ^~
race.cpp:5:12: error: request for member 'second' in 'v', which is of non-class type 'int'
    5 | #define ss second
      |            ^~~~~~
race.cpp:15:56: note: in expansion of macro 'ss'
   15 |   for(int v : adj[u]) if(v.ff != p) dfs(v.ff, u, s + v.ss, d + 1);
      |                                                        ^~
race.cpp: In function 'void merge_dfs(int, int)':
race.cpp:19:16: error: 'k' was not declared in this scope
   19 |   int target = k + 2 * sum[u];
      |                ^