Submission #1022159

#TimeUsernameProblemLanguageResultExecution timeMemory
1022159MarwenElarbiDreaming (IOI13_dreaming)C++17
0 / 100
32 ms12116 KiB
#include <bits/stdc++.h> #include"dreaming.h" using namespace std; #define ll long long #define fi first #define se second #define pb push_back const int nax=1e5+5; vector<bool> vis(nax); pair<pair<int,int>,pair<int,int>> dp[nax]; vector<pair<int,int>> adj[nax]; int res=0; pair<int,int> mx={-1,-1}; void init(int x,int p){ dp[x]={{0,0},{0,0}}; vis[x]=true; for(auto u:adj[x]){ if(u.fi==p) continue; init(u.fi,x); if(u.se+dp[u.fi].fi.fi>dp[x].fi.fi){ dp[x].se=dp[x].fi; dp[x].fi.fi=dp[u.fi].fi.fi+u.se; dp[x].fi.se=u.fi; }else if(u.se+dp[u.fi].fi.fi>dp[x].se.fi){ dp[x].se.fi=dp[u.fi].fi.fi+u.se; dp[x].se.se=u.fi; } } return; } int ans; void dfs(int x,int p){ res=max(res,dp[x].fi.fi+dp[x].se.fi); ans=min(ans,dp[x].fi.fi); for(auto u:adj[x]){ if(u.fi==p) continue; pair<int,int> cur; if(u.fi==dp[x].fi.se){ cur=dp[x].se; cur.fi+=u.se; cur.se=x; }else{ cur=dp[x].fi; cur.fi+=u.se; cur.se=x; } if(cur.fi>dp[u.fi].fi.fi){ dp[u.fi].se=dp[u.fi].fi; dp[u.fi].fi=cur; }else if(cur.fi>dp[u.fi].se.fi){ dp[u.fi].se=cur; } dfs(u.fi,x); } } int travelTime(int N,int M,int L,int A[],int B[],int T[]){ for (int i = 0; i < M; ++i) { adj[A[i]].pb({B[i],T[i]}); adj[B[i]].pb({A[i],T[i]}); } vector<int> tab; for (int i = 0; i < N; ++i) { if(vis[i]) continue; init(i,-1); dfs(i,-1); tab.pb(ans); } sort(tab.rbegin(),tab.rend()); if(tab.size()>1) res=max(res,tab[0]+tab[1]+L); if(tab.size()>2) res=max(res,tab[1]+tab[2]+2*L); return res; }/* int main(){ #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int n,m,l; cin>>n>>m>>l; int a[m]; int b[m]; int t[m]; for (int i = 0; i < m; ++i) { cin>>a[i]>>b[i]>>t[i]; } cout <<travelTime(n,m,l,a,b,t)<<endl; }*/
#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...