#include "dreaming.h"
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <set>
#include <iterator>
#include <stack>
#include <map>
#include <math.h>
#include <bitset>
#include <deque>
#include <string>
#include <tuple>
#include <queue>
#include <numeric>
#include <unordered_set>
#include <unordered_map>
#define pi 3.141592653589793238
#define ll long long
#define ld long double
#define rep(i, a, b) for (long long i = a; i <= b; i++)
#define mod 998244353ll
#define INF 1000000000000000000
#define pb push_back
#define ff first
#define ss second
#define endl '\n'
#define all(x) (x).begin (), (x).end ()
#define sz(x) (ll) (x).size ()
#define reunique(v) v.resize(std::unique(v.begin(), v.end()) - v.begin())
#define rank rnk
#define log lg
#define fast \
ios_base::sync_with_stdio (false); \
cin.tie (NULL); \
cout.tie (NULL)
using namespace std;
ll maxdist;
ll maxvertex;
void dfs(int v, int p, vector <pair<ll,ll>> adj[], vector <bool> &marked, vector <ll> &d, vector <pair<ll,ll>> &par)
{
marked[v]=true;
if(p==-1)
{
d[v]=0;
maxdist=0;
maxvertex=v;
}
else
{
if(d[v]>maxdist)
{
maxdist=d[v];
maxvertex=v;
}
}
for(auto u:adj[v])
if(u.ff!=p)
{
d[u.ff]=u.ss+d[v];
par[u.ff]={v,u.ss};
dfs(u.ff,v,adj,marked,d,par);
}
}
int travelTime(int n, int m, int l, int a[], int b[], int t[]) {
vector <pair<ll,ll>> adj[n+1];
vector <bool> marked(n+1);
vector <ll> d(n+1);
vector <pair<ll,ll>> p(n+1);
rep(i,0,m-1)
{
adj[a[i]].pb({b[i],t[i]});
adj[b[i]].pb({a[i],t[i]});
}
vector <ll> w;
rep(i,0,n-1)
if(!marked[i])
{
dfs(i,-1,adj,marked,d,p);
ll e1=maxvertex;
dfs(e1,-1,adj,marked,d,p);
ll e2=maxvertex;
// cout<<e1<<" "<<e2<<" "<<maxdist<<endl;
if(e1==e2)
{
w.pb(0);
continue;
}
ll v=e2;
ll dnow=0;
while(true)
{
ll last=dnow;
dnow+=p[v].ss;
v=p[v].ff;
if(2*dnow>=maxdist)
{
w.pb(min(dnow,maxdist-last));
break;
}
}
}
// for(auto x:w)
// cout<<x<<" ";
// cout<<endl;
if(sz(w)==1)
return w[0];
else if(sz(w)==2)
return w[0]+w[1]+l;
else
{
sort(all(w));
reverse(all(w));
return max(w[0]+w[1]+l,w[1]+w[2]+2*l);
}
}
// signed main()
// {
// int n=12;
// int m=8;
// int l=2;
// int a[]={0,8,2,5,5,1,1,10};
// int b[]={8,2,7,11,1,3,9,6};
// int t[]={4,2,4,3,7,1,5,3};
// cout<<travelTime(n,m,l,a,b,t);
// return 0;
// }
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
55 ms |
19788 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
55 ms |
19788 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
8092 KB |
Output is correct |
2 |
Correct |
22 ms |
8100 KB |
Output is correct |
3 |
Correct |
21 ms |
8012 KB |
Output is correct |
4 |
Correct |
21 ms |
8152 KB |
Output is correct |
5 |
Correct |
24 ms |
8072 KB |
Output is correct |
6 |
Correct |
27 ms |
9016 KB |
Output is correct |
7 |
Correct |
23 ms |
8448 KB |
Output is correct |
8 |
Correct |
27 ms |
7972 KB |
Output is correct |
9 |
Correct |
30 ms |
7888 KB |
Output is correct |
10 |
Correct |
24 ms |
8316 KB |
Output is correct |
11 |
Correct |
1 ms |
308 KB |
Output is correct |
12 |
Correct |
6 ms |
6220 KB |
Output is correct |
13 |
Correct |
6 ms |
6200 KB |
Output is correct |
14 |
Correct |
6 ms |
6092 KB |
Output is correct |
15 |
Correct |
6 ms |
6220 KB |
Output is correct |
16 |
Correct |
6 ms |
6128 KB |
Output is correct |
17 |
Correct |
6 ms |
6092 KB |
Output is correct |
18 |
Correct |
6 ms |
6220 KB |
Output is correct |
19 |
Correct |
6 ms |
6092 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
436 KB |
Output is correct |
23 |
Correct |
6 ms |
6184 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
55 ms |
19788 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |