제출 #251275

#제출 시각아이디문제언어결과실행 시간메모리
251275AaronNaiduDreaming (IOI13_dreaming)C++14
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> #include "dreaming.h" using namespace std; vector<pair<int, int>> graph[100001]; //int dists[100001]; bool visited[100001]; int maxDist = 0; int maxNode = 0; void dfs(int node, int parent, int dist) { //dists[node] = distance; if (dist > maxDist) { maxDist = dist; maxNode = node; } for (auto i : graph[node]) { if (i.first != parent) { dfs(i.first, node, dist + i.second); } } visited[node] = true; } int travelTime(int n, int m, int l, int a[], int b[], int t[]) { for (int i = 0; i < m; i++) { graph[a[i]].push_back({b[i],t[i]}); graph[b[i]].push_back({a[i], t[i]}); } dfs(0, -1, 0); //cout << "Done dfs1 landed on " << maxNode << "\n"; int dfsFrom = maxNode; maxDist = 0; maxNode = dfsFrom; dfs(dfsFrom, -1, 0); //cout << "Done dfs2 landed on " << maxNode << "\n"; int currDist = maxDist; int prevCurrDist = currDist; int currNode = maxNode; while (float(currDist) > maxDist/float(2)) { for (auto i : graph[currNode]) { if (dists[i.first] < dists[currNode]) { currNode = i.first; prevCurrDist = currDist; currDist = dists[currNode]; break; } } } //cout << "Cand dists are " << currDist << " " << prevCurrDist << " out of " << maxDist << "\n"; int ans1 = min(max(currDist, maxDist - currDist), max(prevCurrDist, maxDist - prevCurrDist)); int start2 = 0; for (int i = 0; i < n; i++) { if (!visited[i]) { //cout << "Starting from " << start2 << "\n"; break; } start2++; } maxDist = 0; maxNode = start2; dfs(start2, -1, 0); //cout << "Done dfs3 landed on " << maxNode << "\n"; dfsFrom = maxNode; maxDist = 0; maxNode = dfsFrom; dfs(dfsFrom, -1, 0); //cout << "Done dfs4 landed on " << maxNode << "\n"; currDist = maxDist; prevCurrDist = currDist; currNode = maxNode; while (float(currDist) > maxDist/float(2)) { for (auto i : graph[currNode]) { if (dists[i.first] < dists[currNode]) { currNode = i.first; prevCurrDist = currDist; currDist = dists[currNode]; break; } } } //cout << "Cand dists are " << currDist << " " << prevCurrDist << " out of " << maxDist << "\n"; int ans2 = min(max(currDist, maxDist - currDist), max(prevCurrDist, maxDist - prevCurrDist)); //cout << "Ans 1 is " << ans1 << "\n"; //cout << "Ans 2 is " << ans2 << "\n"; return ans1 + ans2 + l; }

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

dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:48:17: error: 'dists' was not declared in this scope
             if (dists[i.first] < dists[currNode])
                 ^~~~~
dreaming.cpp:85:17: error: 'dists' was not declared in this scope
             if (dists[i.first] < dists[currNode])
                 ^~~~~