This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
// #pragma optimize("Ofast")
// #pragma target("avx2")
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define pii pair<int,int>
#define all(v) v.begin(),v.end()
#define F first
#define S second
#define mem(a,i) memset(a,i,sizeof(a))
#define sz(s) (int)s.size()
#define y1 yy
#define ppb pop_back
#define lb lower_bound
#define ub upper_bound
#define gcd(a,b) __gcd(a,b)
#define in insert
// #define int ll
const int MAX=1e5+15;
const ll inf=1e9;
const int mod=1e9+7;
const int mod1=1e9+9;
const ld eps=1e-9;
int dx[8]={1,0,-1,0,1,-1,-1,1};
int dy[8]={0,1,0,-1,1,-1,1,-1};
int binpow(int a,int n){
if(!n)return 1;
if(n%2==1)return a*binpow(a,n-1);
int k=binpow(a,n/2);
return k*k;
}
#include "dreaming.h"
int n;
int cmp[MAX];
int d[MAX];
vector<pii> g[MAX];
void dfs(int v,int c){
cmp[v]=c;
for(auto to:g[v]){
if(!cmp[to.F])dfs(to.F,c);
}
}
void dfs1(int v,int p=-1){
for(auto to:g[v]){
if(to.F==p)continue;
d[to.F]=d[v]+to.S;
dfs1(to.F,v);
}
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
assert(M==N-2);
n=N;
for(int i=0;i<M;i++){
g[A[i]+1].pb({B[i]+1,T[i]});
g[B[i]+1].pb({A[i]+1,T[i]});
}
int cnt=0;
int ans=inf;
for(int i=1;i<=n;i++){
if(!cmp[i]){
dfs(i,++cnt);
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
if(cmp[i]==cmp[j])continue;
d[i]=d[j]=0;
dfs1(i);
dfs1(j);
int c1=0,c2=0;
for(int k=1;k<=n;k++){
if(cmp[i]==cmp[k]){
c1=max(c1,d[k]);
}
else{
c2=max(c2,d[k]);
}
}
ans=min(ans,L+c1+c2);
}
}
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |