제출 #90173

#제출 시각아이디문제언어결과실행 시간메모리
90173FiloSanzaDreaming (IOI13_dreaming)C++14
0 / 100
1069 ms7544 KiB
#pragma GCC optimize("O3") #include "dreaming.h" #include <bits/stdc++.h> const int INF = 2e9; using namespace std; struct arco { int to, p; }; int N; vector<vector<arco>> g; vector<int> dist; vector<pair<int, int>> centers; vector<int> temp; vector<int> padre; queue<int> changed; int bfs(int node, bool precalcolo){ queue<int> q; dist[node] = 0; q.push(node); int maxiNode = node; int maxi = 0; while(!q.empty()){ auto curr = q.front(); q.pop(); if(maxi < dist[curr]) maxi = dist[curr], maxiNode = curr; for(auto i : g[curr]){ if(dist[i.to] > dist[curr] + i.p){ padre[i.to] = curr; changed.push(i.to); q.push(i.to); dist[i.to] = dist[curr] + i.p; } } } // for(auto i : padre)cout << i << " "; // cout << "\n\n"; if(precalcolo) temp.push_back(maxiNode); else{ int diameter = maxi; int center = maxiNode; int curr = maxiNode; maxi = maxi; // cout << curr <<"\n"; // cout << "\t" << max(diameter-dist[curr], dist[curr]) << " " << maxi << "\n"; while(padre[curr] != -1){ //cout << curr << " " << padre[curr] << "\n"; curr = padre[curr]; //cout << curr << "\n"; if(max(diameter-dist[curr], dist[curr]) < maxi){ //cout << "\t" << max(diameter-dist[curr], dist[curr]) << " " << maxi << "\n"; maxi = max(diameter-dist[curr], dist[curr]); center = curr; } } centers.push_back({maxi, center}); } while(!changed.empty()){ padre[changed.front()] = -1; changed.pop(); } return *max_element(dist.begin(), dist.end()); } int travelTime(int N, int M, int L, int A[], int B[], int T[]) { ::N = N; g.resize(N); dist.resize(N); centers.reserve(N); temp.reserve(N); padre.resize(N, -1); for(int i=0; i<M; i++){ g[A[i]].push_back({B[i], T[i]}); g[B[i]].push_back({A[i], T[i]}); } fill(dist.begin(), dist.end(), INF); for(int i=0; i<N; i++) if(dist[i] == INF) bfs(i, true); fill(dist.begin(), dist.end(), INF); for(auto i : temp) bfs(i, false); nth_element(centers.begin(), centers.begin()+centers.size()-2, centers.end()); return centers.empty() ? *max_element(dist.begin(), dist.end()) : (L + centers.back().first + centers[centers.size()-2].first); }

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

dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:93:28: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
     for(int i=0; i<N; i++) if(dist[i] == INF)
                            ^~
dreaming.cpp:96:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
  fill(dist.begin(), dist.end(), INF);
  ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...