//Bismillahirrahmanirrahim
#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long lo;
typedef pair< int,int > PII;
#define fi first
#define se second
#define mp make_pair
#define endl "\n"
#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 inf = 2000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 500005;
const lo mod = 1000000007;
int n,m,b[li],a[li],k,flag,t,co[li],vis[li],mx[li],mn;
int cev;
string s;
vector<PII> v[li];
vector<int> vec;
inline void dfs(int node,int ata){
vis[node]=1;
for(int i=0;i<(int)v[node].size();i++){
int go=v[node][i].fi;
if(go==ata)continue;
dfs(go,node);
co[node]=max(co[node],co[go]+v[node][i].se);
}
//~ cout<<node<<endl;
mx[node]=max(mx[node],co[node]);
}
inline void dfs1(int node,int ata,int der){
vis[node]=1;
multiset<int> st;
for(int i=0;i<(int)v[node].size();i++){
int go=v[node][i].fi;
if(go==ata)continue;
st.insert(co[go]+v[node][i].se);
}
int der1=der;
for(int i=0;i<(int)v[node].size();i++){
int go=v[node][i].fi;
if(go==ata)continue;
auto it=st.end();
it--;
if(*it==co[go]+v[node][i].se){
if(it!=st.begin()){
it--;
der1=max(der1,*it);
}
}
else der1=max(der1,*it);
dfs1(go,node,der1+v[node][i].se);
}
mx[node]=max(mx[node],der1);
cev=max(cev,mx[node]);
mn=min(mn,mx[node]);
}
int travelTime(int n, int m, int l, int A[], int B[], int T[]) {
for(int i=0;i<m;i++){
v[A[i]].pb({B[i],T[i]});
v[B[i]].pb({A[i],T[i]});
}
FOR{
if(vis[i])continue;
mn=inf;
dfs(i,-1);
dfs1(i,-1,0);
vec.pb(mn);
}
sort(vec.begin(),vec.end());
reverse(vec.begin(),vec.end());
for(int i=1;i<(int)vec.size();i++){
cev=max(cev,vec[0]+vec[i]+l);
}
for(int i=2;i<(int)vec.size();i++){
cev=max(cev,vec[1]+vec[i]+2*l);
}
return cev;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
87 ms |
28536 KB |
Output is correct |
2 |
Incorrect |
89 ms |
27768 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
87 ms |
28536 KB |
Output is correct |
2 |
Incorrect |
89 ms |
27768 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
87 ms |
28536 KB |
Output is correct |
2 |
Incorrect |
89 ms |
27768 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
16252 KB |
Output is correct |
2 |
Correct |
40 ms |
16376 KB |
Output is correct |
3 |
Correct |
37 ms |
16248 KB |
Output is correct |
4 |
Correct |
35 ms |
16376 KB |
Output is correct |
5 |
Correct |
35 ms |
16288 KB |
Output is correct |
6 |
Correct |
39 ms |
16760 KB |
Output is correct |
7 |
Correct |
37 ms |
16504 KB |
Output is correct |
8 |
Correct |
35 ms |
16256 KB |
Output is correct |
9 |
Correct |
34 ms |
16244 KB |
Output is correct |
10 |
Correct |
38 ms |
16500 KB |
Output is correct |
11 |
Correct |
8 ms |
12160 KB |
Output is correct |
12 |
Correct |
13 ms |
13820 KB |
Output is correct |
13 |
Correct |
13 ms |
13820 KB |
Output is correct |
14 |
Correct |
12 ms |
13820 KB |
Output is correct |
15 |
Correct |
13 ms |
13820 KB |
Output is correct |
16 |
Correct |
12 ms |
13820 KB |
Output is correct |
17 |
Correct |
12 ms |
13564 KB |
Output is correct |
18 |
Correct |
14 ms |
13948 KB |
Output is correct |
19 |
Correct |
12 ms |
13820 KB |
Output is correct |
20 |
Correct |
9 ms |
12084 KB |
Output is correct |
21 |
Correct |
9 ms |
12032 KB |
Output is correct |
22 |
Correct |
8 ms |
12160 KB |
Output is correct |
23 |
Correct |
12 ms |
13820 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
87 ms |
28536 KB |
Output is correct |
2 |
Incorrect |
89 ms |
27768 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
87 ms |
28536 KB |
Output is correct |
2 |
Incorrect |
89 ms |
27768 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |