#include <bits/stdc++.h>
#include "dreaming.h"
using namespace std;
#ifdef LOCAL
#define deb(...) logger(#__VA_ARGS__, __VA_ARGS__)
template<typename ...Args>
void logger(string vars, Args&&... values) {
cerr<<vars<<" = ";
string delim="";
(...,(cerr<<delim<<values,delim=", "));
cerr<<"\n";
}
#else
#define deb(...) logger(#__VA_ARGS__, __VA_ARGS__)
template<typename ...Args>
void logger(string vars, Args&&... values) {}
#endif
#define pb push_back
#define sz(x) (int)(x.size())
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<typename T> inline void maxa(T& a,T b){a=max(a,b);}
template<typename T> inline void mina(T& a,T b){a=min(a,b);}
const int mxN=1e5+5;
vector<pii> graph[mxN];
ll dist[mxN];
int ep,seen[mxN];
vector<int> path;
void dfs(int at,int p){
path.pb(dist[at]);
seen[at]=1;
if(dist[at]>dist[ep])
ep=at;
for(pii &i:graph[at]){
if(i.first!=p){
dist[i.first]=dist[at]+i.second;
dfs(i.first,at);
}
}
}
void merge(pii &a,pii &b,int L){
if(max(a.first,b.first)>a.second+b.second+L){
a.first=max(a.first,b.first);
} else{
a.first=a.second+b.second+L;
a.second=min(a.second,b.second)+L;
}
}
int travelTime(int N,int M,int L,int A[],int B[],int T[]){
for(int i=0;i<M;i++){
graph[A[i]].pb({B[i],T[i]});
graph[B[i]].pb({A[i],T[i]});
}
vector<pii> all;
for(int i=0;i<N;i++){
if(seen[i])
continue;
ep=N;
dfs(i,-1);
path.clear();
dist[ep]=0;
dfs(ep,-1);
all.pb({dist[ep],*lower_bound(path.begin(),path.end(),dist[ep]/2)});
deb(i,all.back().first,all.back().second);
path.clear();
}
pii ans=all[0];
deb(ans.first,ans.second);
for(int i=1;i<sz(all);i++){
merge(ans,all[i],L);
deb(ans.first,ans.second);
}
return ans.first;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
59 ms |
15240 KB |
Output is correct |
2 |
Correct |
54 ms |
15132 KB |
Output is correct |
3 |
Correct |
34 ms |
10976 KB |
Output is correct |
4 |
Correct |
8 ms |
4556 KB |
Output is correct |
5 |
Correct |
7 ms |
3660 KB |
Output is correct |
6 |
Correct |
13 ms |
5452 KB |
Output is correct |
7 |
Incorrect |
2 ms |
2636 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
2636 KB |
Output is correct |
4 |
Incorrect |
2 ms |
2636 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
59 ms |
15240 KB |
Output is correct |
2 |
Correct |
54 ms |
15132 KB |
Output is correct |
3 |
Correct |
34 ms |
10976 KB |
Output is correct |
4 |
Correct |
8 ms |
4556 KB |
Output is correct |
5 |
Correct |
7 ms |
3660 KB |
Output is correct |
6 |
Correct |
13 ms |
5452 KB |
Output is correct |
7 |
Incorrect |
2 ms |
2636 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
26 ms |
6636 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
2636 KB |
Output is correct |
4 |
Incorrect |
2 ms |
2636 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
59 ms |
15240 KB |
Output is correct |
2 |
Correct |
54 ms |
15132 KB |
Output is correct |
3 |
Correct |
34 ms |
10976 KB |
Output is correct |
4 |
Correct |
8 ms |
4556 KB |
Output is correct |
5 |
Correct |
7 ms |
3660 KB |
Output is correct |
6 |
Correct |
13 ms |
5452 KB |
Output is correct |
7 |
Incorrect |
2 ms |
2636 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |