Submission #967780

#TimeUsernameProblemLanguageResultExecution timeMemory
967780Hugo1729Dreaming (IOI13_dreaming)C++17
18 / 100
25 ms11856 KiB
#include <bits/stdc++.h> #include "dreaming.h" using namespace std; #define f first #define s second vector<pair<int,int>> adj[100000]; pair<int,pair<int,int>> dp[100000]; bool marked[100000]={0}; int dfs_sizes(int v, int pV){ dp[v]={-1,{0,0}}; marked[v]=1; for(auto [w,d] : adj[v]){ if(w!=pV){ int sus=dfs_sizes(w,v)+d; if(sus>dp[v].s.f)dp[v]={w,{sus,dp[v].s.f}}; else if(sus>dp[v].s.s)dp[v].s.s=sus; } } // cout << v << ' ' << dp[v].f << ' ' << dp[v].s.f <<' ' << dp[v].s.s << '\n'; return dp[v].s.f; } int dfs(int v, int pV=-1, int d=0){ // cout << "d" << v << ' ' << d << '\n'; if(dp[v].f!=-1){ int sus=max(dp[dp[v].f].s.s,d+dp[v].s.f-dp[dp[v].f].s.f+dp[v].s.s); if(max(sus,dp[dp[v].f].s.f)<max(d,dp[v].s.f))return dfs(dp[v].f,v,sus); else return max(d,dp[v].s.f); } return max(d,dp[v].s.f); } 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_sizes(i,i); sussy.push_back(-dfs(i)); // cout <<i << ' ' << sussy[sussy.size()-1] << '\n'; } // cout << i << ' ' << dp[i].first << ' ' << dp[i].second << '\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); }
#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...