제출 #1074637

#제출 시각아이디문제언어결과실행 시간메모리
1074637Trumling꿈 (IOI13_dreaming)C++14
47 / 100
66 ms20176 KiB
#include "dreaming.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; #define pb push_back #define F first #define S second #define enter cout<<'\n'; #define INF 99999999999999999 #define MOD 1000000007 #define all(x) x.begin(),x.end() vector<vector<pair<ll,ll>>>g; vector<bool>vis; vector<ll>dist,par; ll n,m; void dfs1(int start,int pre,ll &maxi) { for(auto x:g[start]) if(x.F!=pre) { par[x.F]=start; vis[x.F]=1; dist[x.F]= dist[start] + x.S; if(dist[maxi]<dist[x.F]) maxi=x.F; dfs1(x.F, start,maxi); } } void dfs2(int start,int pre,ll &ans,ll diff,ll curr,ll count) { for(auto x:g[start]) if(x.F!=pre) dfs2(x.F,start,ans,diff,curr + x.S,count); } int travelTime(int N, int M, int L, int A[], int B[], int T[]) { n=N; m=M; g.assign(n,vector<pair<ll,ll>>()); vis.assign(n,0); dist.assign(n,0); par.assign(n,0); for(int i=0;i<m;i++) { g[A[i]].pb({B[i],T[i]}); g[B[i]].pb({A[i],T[i]}); } vector<ll>ans(3,0); ll idx=0; for(int i=0;i<N;i++) if(!vis[i]) { vis[i]=1; ll p1=i,p2; dfs1(i,i,p1); dist[p1]=0; p2=p1; dfs1(p1,p1,p2); ll curr=0; ll diff=INF; ll count=dist[p2]; ans[2]=max(ans[2],dist[p2]); while(p2!=p1) { if(diff > abs((count-curr)-curr)) { ans[idx]=max(curr,count-curr); diff= abs((count-curr)-curr); } curr+=dist[p2]-dist[par[p2]]; p2=par[p2]; } idx++; } return max(ans[2],ans[0] + ans[1] + 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...