제출 #978159

#제출 시각아이디문제언어결과실행 시간메모리
978159LOLOLOTraffic (IOI10_traffic)C++17
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> #define ll long long using namespace std; #define f first #define s second #define pb push_back #define ep emplace #define eb emplace_back #define lb lower_bound #define ub upper_bound #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define uniquev(v) sort(all(v)), (v).resize(unique(all(v)) - (v).begin()) #define mem(f,x) memset(f , x , sizeof(f)) #define sz(x) (int)(x).size() #define __lcm(a, b) (1ll * ((a) / __gcd((a), (b))) * (b)) #define mxx *max_element #define mnn *min_element #define cntbit(x) __builtin_popcountll(x) #define len(x) (int)(x.length()) const int N = 3e5 + 10; vector <int> ed[N]; ll f[N], a[N]; void dfs(int u, int v) { for (auto x : ed[u]) { if (x == v) continue; dfs(x, u); f[u] = max(f[u], f[x] + a[x]); } } //before -> u is v's parent void reroot(int u, int v) { f[v] = max(f[v], f[u] + a[u]); } ll ans = 1e18, id = 0; void dfs2(int u, int v) { if (ans > f[u]) { ans = f[u]; id = u; } sort(all(ed[u]), [&] (int x, int y) {return f[x] + a[x] > f[y] + a[y];}); for (int i = 0; i < sz(ed[u]); i++) { int x = ed[u][i]; if (x == v) continue; ll a = f[u], b = f[x]; if (i == sz(ed[u]) - 1) { f[u] = 0; } else { if (i == 0) { f[u] = f[ed[u][1]] + a[ed[u][1]]; } else { f[u] = f[ed[u][0]] + a[ed[u][0]]; } } reroot(u, x); dfs2(x, u); f[u] = a, f[x] = b; } } int LocateCentre(int N, int P[], int S[], int D[]) { ans = 1e18; for (int i = 0; i < n - 1; i++) { ed[S[i]].pb(D[i]); ed[D[i]].pb(S[i]); } for (int i = 1; i <= n; i++) a[i] = P[i - 1]; dfs(1, 1); dfs2(1, 1); return id; }

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

traffic.cpp: In function 'void dfs2(int, int)':
traffic.cpp:60:39: error: invalid types 'long long int[__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type {aka int}]' for array subscript
   60 |                 f[u] = f[ed[u][1]] + a[ed[u][1]];
      |                                       ^
traffic.cpp:62:39: error: invalid types 'long long int[__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type {aka int}]' for array subscript
   62 |                 f[u] = f[ed[u][0]] + a[ed[u][0]];
      |                                       ^
traffic.cpp: In function 'int LocateCentre(int, int*, int*, int*)':
traffic.cpp:74:25: error: 'n' was not declared in this scope
   74 |     for (int i = 0; i < n - 1; i++) {
      |                         ^
traffic.cpp:79:26: error: 'n' was not declared in this scope
   79 |     for (int i = 1; i <= n; i++)
      |                          ^