Submission #234093

#TimeUsernameProblemLanguageResultExecution timeMemory
234093tleontest1Dreaming (IOI13_dreaming)C++14
100 / 100
154 ms16632 KiB
#include <dreaming.h> #include <bits/stdc++.h> using namespace std; typedef long long lo; typedef pair< lo,lo > PII; #define fi first #define se second #define mp make_pair #define pb push_back #define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define FOR for(int i=0;i<N;i++) #define mid ((start+end)/2) #define ort ((bas+son)/2) const lo MAX = -1000000000000000000; const lo MIN = 1000000000000000000; const lo inf = 3000000000; const lo KOK = 100000; const lo LOG = 30; const lo li = 100005; const lo mod = 1000000007; lo n,m,b[li],a[li],k,flag,t[li],l,mx,mx1,maxi[li],say,mn[li],ind,maxx,maxxx,maxx1,maxx2; lo cev; string s; lo ok[li]; vector<PII> v[li]; inline void dfs(lo node,lo ata,lo der,lo basla){ //~ cout<<node<<" : : "<<ata<<endl; for(lo i=0;i<(lo)v[node].size();i++){ int go=v[node][i].fi; int co=v[node][i].se; if(go==ata)continue; dfs(go,node,der+co,basla); } if(!ok[node])ok[node]=say; if(der>mx)ind=node; mx=max(mx,der); maxxx=max(maxxx,mx); maxi[node]=max(maxi[node],der); } int travelTime(int N, int M, int L, int A[], int B[], int T[]) { for(lo i=0;i<M;i++){ v[A[i]].pb(mp(B[i],T[i])); v[B[i]].pb(mp(A[i],T[i])); } FOR mn[i]=inf; say=1; dfs(0,-1,0,0); mx=0; dfs(ind,-1,0,ind); mx1=mx; mx=0; dfs(ind,-1,0,ind); mx=0; for(lo i=0;i<N;i++){ if(!ok[i]){say++;mx=0;dfs(i,-1,0,i);mx=0;dfs(ind,-1,0,ind);mx=0;dfs(ind,-1,0,ind);} } FOR{ //~ cout<<ok[i]<<endl; mn[ok[i]]=min(mn[ok[i]],maxi[i]); } cev=0; //~ cout<<say<<"**\n"; //~ say=2; for(lo i=1;i<=say;i++){ cev+=mn[i]; maxx2=max(maxx2,mn[i]); if(maxx2>maxx1)swap(maxx2,maxx1); if(maxx1>maxx)swap(maxx,maxx1); //~ cout<<mn[i]<<endl; } if(say==1){maxx1=-inf;maxx2=-inf;} if(say==2){maxx2=-inf;} cev=maxx+maxx1; //~ cout<<mx<<" : ; "<<mx1<<endl; return max(maxxx,max(cev+(L),maxx2+maxx1+2*L)); }
#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...