Submission #968142

#TimeUsernameProblemLanguageResultExecution timeMemory
968142Hugo1729Dreaming (IOI13_dreaming)C++11
18 / 100
50 ms12324 KiB
#include <bits/stdc++.h> #include "dreaming.h" using namespace std; #define f first #define s second vector<pair<int,int>> adj[100000]; int dp1[100000],dp2[100000],dp3[100000]; bool marked[100000]={0}; int dfs_sizes1(int v, int pV){ dp1[v]=0; dp2[v]=0; marked[v]=1; for(auto [w,d] : adj[v]){ if(w!=pV){ int sus=dfs_sizes1(w,v)+d; if(sus>dp1[v]){ dp2[v]=dp1[v]; dp1[v]=sus; }else if(sus>dp2[v]){ dp2[v]=sus; } } } return dp1[v]; } void dfs_sizes2(int v, int pV){ for(auto [w,d] : adj[v]){ if(w!=pV){ if(dp1[w]+d==dp1[v]){ dp3[w]=max(dp2[v],dp3[v])+d; }else{ dp3[w]=max(dp1[v],dp3[v])+d; } dfs_sizes2(w,v); } } } int dfs_final(int v, int pV){ int ans=max(dp1[v],dp3[v]); for(auto [w,d] : adj[v]){ if(w!=pV){ ans=min(ans,dfs_final(w,v)); } } return ans; } int travelTime(int N, int M, int L, int A[], int B[], int T[]) { for(int i=0;i<M;i++){ adj[A[i]].push_back({B[i],T[i]}); adj[B[i]].push_back({A[i],T[i]}); } vector<int> sussy; for(int i=0;i<N;i++){ if(!marked[i]){ dfs_sizes1(i,i); dfs_sizes2(i,i); sussy.push_back(-dfs_final(i,i)); // cout <<i << ' ' << sussy[sussy.size()-1] << '\n'; } // cout << i << ' ' << dp1[i].first << ' ' << dp1[i].second << '\n'; } for(int i=0;i<N;i++){ // cout << i << ' ' << dp1[i] << ' ' << dp2[i] << ' ' << dp3[i] << '\n'; } sort(sussy.begin(),sussy.end()); if(sussy.size()==1)return -sussy[0]; else if(sussy.size()==2)return -sussy[0]-sussy[1]+L; return max(-sussy[0]-sussy[1]+L,-sussy[2]-sussy[1]+L*2); }

Compilation message (stderr)

dreaming.cpp: In function 'int dfs_sizes1(int, int)':
dreaming.cpp:16:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   16 |     for(auto [w,d] : adj[v]){
      |              ^
dreaming.cpp: In function 'void dfs_sizes2(int, int)':
dreaming.cpp:31:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   31 |     for(auto [w,d] : adj[v]){
      |              ^
dreaming.cpp: In function 'int dfs_final(int, int)':
dreaming.cpp:46:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   46 |     for(auto [w,d] : adj[v]){
      |              ^
#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...