Submission #96983

#TimeUsernameProblemLanguageResultExecution timeMemory
96983E869120Dreaming (IOI13_dreaming)C++14
18 / 100
100 ms20724 KiB
#include "dreaming.h" #include <bits/stdc++.h> using namespace std; vector<pair<int, int> >X[1<<18]; vector<int> J[1<<18], G; int N, M, L, EA, EB, col[1<<18], cnts, dist[1<<18], dist2[1<<18]; void dfs(int pos){ if(col[pos]>=1) return; col[pos]=cnts; J[cnts].push_back(pos); for(int i=0;i<X[pos].size();i++) dfs(X[pos][i].first); } void getdist(int pos){ queue<int>que; que.push(pos); dist[pos]=0; while(!que.empty()){ int p = que.front(); que.pop(); for(int i=0;i<(int)X[p].size();i++) { int to = X[p][i].first; if(dist[to]>dist[p]+X[p][i].second){ dist[to]=dist[p]+X[p][i].second; que.push(to); } } } } pair<int, int> radius(int pos){ // 1. get dist(1, a) int cols = pos; pos = J[pos][0]; for(int i=0;i<J[pos].size();i++) dist[J[pos][i]]=(1<<30); getdist(pos); int maxp=-1; for(int i:J[cols]){ if(maxp<dist[i]) {maxp = dist[i]; pos = i;} } // 2. get dist(a, b) queue<int>que; for(int i=0;i<(int)J[cols].size();i++) dist2[J[cols][i]]=(1<<30); que.push(pos); dist2[pos]=0; while(!que.empty()){ int p = que.front(); que.pop(); for(int i=0;i<(int)X[p].size();i++) { int to = X[p][i].first; if(dist2[to]>dist2[p]+X[p][i].second){ dist2[to]=dist2[p]+X[p][i].second; que.push(to); } } } int ans=-1; EA=pos; for(int i:J[cols]) { if(ans<dist2[i]){ans=dist2[i];EB=i;} } // 3. get dist(b, a) for(int i:J[cols]) dist[i]=(1<<30); getdist(EB); int ans2=ans; for(int i:J[cols]){ if(dist[i]+dist2[i]==dist2[EB]) ans2 = min(ans2, max(dist[i], dist2[i])); } return make_pair(ans, ans2); } int travelTime(int NN, int MM, int LL, int A[], int B[], int T[]) { N = NN; M = MM; L = LL; for(int i=0;i<M;i++){ X[A[i]].push_back(make_pair(B[i], T[i])); X[B[i]].push_back(make_pair(A[i], T[i])); } for(int i=1;i<=N;i++){ if(col[i]>=1) continue; cnts++;dfs(i); } int maxn=0; for(int i=1;i<=cnts;i++){ pair<int, int>I1 = radius(i); maxn = max(maxn, I1.first); //cout<<i<<":"<<I1.first<<" "<<I1.second<<endl; G.push_back(I1.second); } sort(G.begin(), G.end()); reverse(G.begin(), G.end()); if(G.size()==1) return maxn; int rem=(1<<30); for(int i=0;i<(int)G.size();i++){ int v1 = G[i]; vector<int>v2; for(int j=0;j<(int)G.size();j++){ if(j != i) v2.push_back(G[j]); if(v2.size()==2) break; } int s1 = v1 + v2[0] + L; int s2 = 0; if(v2.size()==2) s2 = v2[0] + v2[1] + L * 2; rem = min(rem, max(s1, s2)); } return max(maxn, rem); }

Compilation message (stderr)

dreaming.cpp: In function 'void dfs(int)':
dreaming.cpp:11:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<X[pos].size();i++) dfs(X[pos][i].first);
              ~^~~~~~~~~~~~~~
dreaming.cpp: In function 'std::pair<int, int> radius(int)':
dreaming.cpp:33:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<J[pos].size();i++) dist[J[pos][i]]=(1<<30);
              ~^~~~~~~~~~~~~~
#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...