//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,maxi,ind;
int cev;
string s;
vector<PII> v[li];
vector<int> vec;
//~ int A[li],B[li],T[li];
inline void dfs(int node,int ata,int der){
vis[node]=1;
int mx1=0,mx2=0;
for(int i=0;i<(int)v[node].size();i++){
int go=v[node][i].fi;
if(go==ata)continue;
dfs(go,node,der+v[node][i].se);
}
if(maxi<der)ind=node;
maxi=max(maxi,der);
mx[node]=max(mx[node],der);
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;
maxi=0;
ind=i;
dfs(i,-1,0);
mn=inf;
//~ ind=i;
maxi=0;
dfs(ind,-1,0);
maxi=0;
//~ ind=i;
mn=inf;
dfs(ind,-1,0);
//~ cout<<mn<<endl;
vec.pb(mn);
}
sort(vec.begin(),vec.end());
reverse(vec.begin(),vec.end());
//~ for(int i=0;i<(int)vec.size();i++)cout<<vec[i]<<endl;
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;
}
Compilation message
dreaming.cpp: In function 'void dfs(int, int, int)':
dreaming.cpp:35:6: warning: unused variable 'mx1' [-Wunused-variable]
35 | int mx1=0,mx2=0;
| ^~~
dreaming.cpp:35:12: warning: unused variable 'mx2' [-Wunused-variable]
35 | int mx1=0,mx2=0;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
75 ms |
22392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
75 ms |
22392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
75 ms |
22392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
15480 KB |
Output is correct |
2 |
Correct |
34 ms |
15608 KB |
Output is correct |
3 |
Correct |
38 ms |
15488 KB |
Output is correct |
4 |
Correct |
33 ms |
15480 KB |
Output is correct |
5 |
Correct |
37 ms |
15516 KB |
Output is correct |
6 |
Correct |
37 ms |
16120 KB |
Output is correct |
7 |
Correct |
35 ms |
15736 KB |
Output is correct |
8 |
Correct |
34 ms |
15488 KB |
Output is correct |
9 |
Correct |
34 ms |
15488 KB |
Output is correct |
10 |
Correct |
35 ms |
15616 KB |
Output is correct |
11 |
Correct |
8 ms |
12032 KB |
Output is correct |
12 |
Correct |
12 ms |
13564 KB |
Output is correct |
13 |
Correct |
13 ms |
13564 KB |
Output is correct |
14 |
Correct |
12 ms |
13564 KB |
Output is correct |
15 |
Correct |
12 ms |
13564 KB |
Output is correct |
16 |
Correct |
12 ms |
13564 KB |
Output is correct |
17 |
Correct |
13 ms |
13436 KB |
Output is correct |
18 |
Correct |
13 ms |
13564 KB |
Output is correct |
19 |
Correct |
12 ms |
13564 KB |
Output is correct |
20 |
Correct |
8 ms |
12032 KB |
Output is correct |
21 |
Correct |
8 ms |
12032 KB |
Output is correct |
22 |
Correct |
9 ms |
12160 KB |
Output is correct |
23 |
Correct |
12 ms |
13564 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
75 ms |
22392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
75 ms |
22392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |