#include <bits/stdc++.h>
#include "dreaming.h"
#define mp make_pair
#define pb push_back
#define ld long double
#define pii pair<int,int>
#define sz(x) (int)x.size()
#define piii pair<pii,pii>
#define precise cout<<fixed<<setprecision(10)
#define st first
#define nd second
#define ins insert
#define vi vector<int>
using namespace std;
const int MAX=1e5+5;
vector<pii>P[MAX];
int dist[MAX];
int ojciec[MAX];
vi mids;
bool O[MAX];
pii get_far(int u,int fa)
{
pii akt=mp(dist[u],u);
ojciec[u]=fa;
O[u]=true;
for (auto it:P[u])
if (it.st!=fa)
{
dist[it.st]=dist[fa]+it.nd;
pii wez=get_far(it.st,u);
if (wez.st>akt.st)akt=wez;
}
return akt;
}
void get_mid(int from,int ile)
{
int maxi=0;
while (from!=-1)
{
maxi=max(maxi,max(dist[from],ile-dist[from]));
from=ojciec[from];
}
}
void func(int u)
{
dist[u]=0;
pii v=get_far(u,-1);
int root=v.nd;
pii znajdz=get_far(root,-1);
int dist=znajdz.st;
int wskaz=znajdz.nd;
get_mid(wskaz,dist);
}
int travelTime(int n,int m,int l,int a[],int b[],int t[])
{
int ans=0;
for (int i=0;i<m;i++)
{
int x=a[i];
int y=b[i];
int c=t[i];
x++,y++;
P[x].pb(mp(y,c));
P[y].pb(mp(x,c));
}
for (int i=1;i<=n;i++)
if (!O[i])func(i);
sort(mids.begin(),mids.end(),greater<int>());
if (m==n-1)ans=max(ans,mids[0]);
if (m<=n-2)ans=max(ans,mids[0]+mids[1]+l);
if (m<=n-3)ans=max(ans,mids[1]+mids[2]+l*2);
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
75 ms |
29176 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
75 ms |
29176 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
75 ms |
29176 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
31 ms |
11648 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
75 ms |
29176 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
75 ms |
29176 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |