Submission #672600

#TimeUsernameProblemLanguageResultExecution timeMemory
672600Hacv16Dreaming (IOI13_dreaming)C++17
Compilation error
0 ms0 KiB
#include<bits/stdc++.h> #include"dreaming.h" using namespace std; const int MAX = 2e6 + 15; const int INF = 0x3f3f3f3f; #define fr first #define sc second int mxdiam, dist[MAX], pai[MAX], seen[MAX]; vector<pair<int, int>> adj[MAX]; int mx, id; void dfs(int u, int p, int d, bool f){ seen[u] = true; mxdiam = max(d, mxdiam); if(d > mx) mx = d, id = u; if(f) pai[u] = p, dist[u] = d; for(auto e : adj[u]){ int v = e.fr, w = e.sc; if(v == p) continue; dfs(v, u, d + w, f); } } int getRadius(int u){ mx = -1, id = 0; dfs(u, -1, 0, 0); int ponta1 = id; mx = -1, id = 0; dfs(ponta1, -1, 0, 1); vector<int> path; int ponta2 = id; int cur = ponta2; while(cur != -1){ path.push_back(cur); cur = pai[cur]; } int mndiff = INF, idx = u; for(auto c : path){ int cur = abs(dist[c] - (dist[ponta2] - dist[c])); if(cur < mndiff) mndiff = cur, idx = c; } return max(dist[idx], dist[ponta2] - dist[idx]); } int travelTime(int n, int m, int L, int A[], int B[], int T[]){ for(int i = 0; i < m; i++){ int u = A[i], v = B[i], w = T[i]; adj[u].push_back({v, w}); adj[v].push_back({u, w}); } vector<int> rad; for(int i = 0; i < n; i++){ if(seen[i]) continue; int r = getRadius(i); rad.push_back(r); } sort(rad.begin(), rad.end()); int op1 = (rad[i].size() > 1 ? L + rad.back() + rad[rad.size() - 2] : INF); int op2 = (rad[i].size() > 2 ? 2 * L + rad[rad.size() - 2] + rad[rad.size() - 3] : INF); return max(mxdiam, min(op1, op2)); }

Compilation message (stderr)

dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:76:17: error: 'i' was not declared in this scope
   76 |  int op1 = (rad[i].size() > 1 ? L + rad.back() + rad[rad.size() - 2] : INF);
      |                 ^