#include <bits/stdc++.h>
#include "dreaming.h"
using namespace std;
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
//#undef LOCALKL
#define IO \
ios_base::sync_with_stdio(0);(cin).tie(0);(cout).tie(0)
#define y1 y1_
#define prev prev_
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define eb emplace_back
#define F first
#define S second
#ifdef LOCALKL
#define cerr cerr<<"\33[1;32m"
#define cout cout<<"\33[0m"
#else
#define endl '\n'
#define cerr if(1){}else cerr
#endif
#define OK cout<<"OK\n"<<endl;
#define setpre(k) fixed<<setprecision(k)
#define mmset(k,y) memset(k,y,sizeof(k))
#define sz(x) ((int)(x).size())
using pii = pair<int,int>;
using pll = pair<long long,long long>;
using ull = unsigned long long;
using intt = long long;
using ll = long long;
using ld = long double;
const ll m9 = 998244353;
const ll m7 = 1000000007;
const ll m18 = 1000000000000000000;
const ll i127 = 2139062143;
const ll l127 = 9187201950435737471;
vector<pii>g[100001];
pii mx;
int res, ans;
int d[100001];
void dfs(int v)
{
for(auto u : g[v])
{
if(d[u.F]==-1)
{
d[u.F] = d[v] + u.S;
mx = max(make_pair(d[u.F], u.F), mx);
dfs(u.F);
}
}
}
int dfs1(int v, int par, int dis)
{
int cdis = 0;
for(auto u : g[v])
if(u.F!=par)
{
cdis = max(cdis, dfs1(u.F, v, dis+u.S)+u.S);
}
ans = max(ans, cdis+dis);
res = min(res, max(cdis, dis));
return cdis;
}
vector<int>c;
int travelTime(int n, int m, int L, int A[], int B[], int T[]) {
memset(d, -1, sizeof(d));
for(int i=0;i<m;i++)
{
g[A[i]].emplace_back(B[i],T[i]);
g[B[i]].emplace_back(A[i],T[i]);
}
for(int i=0;i<n;i++)
if(d[i]==-1)
{
d[i]=0;
mx={0,i};
dfs(i);
// cerr<<mx.S<<endl;
res = INT_MAX;
dfs1(mx.S, -1, 0);
//cerr<<res<<endl;
c.emplace_back(res);
}
sort(all(c), greater<int>());
if(m<n-2)
ans = max(ans, max(c[0]+c[1]+L, c[1]+c[2]+L+L));
else if(m==n-2)
ans = max(ans, c[0]+c[1]+L);
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
65 ms |
15324 KB |
Output is correct |
2 |
Correct |
51 ms |
15280 KB |
Output is correct |
3 |
Correct |
36 ms |
11132 KB |
Output is correct |
4 |
Correct |
9 ms |
4864 KB |
Output is correct |
5 |
Correct |
8 ms |
3916 KB |
Output is correct |
6 |
Correct |
14 ms |
5708 KB |
Output is correct |
7 |
Correct |
2 ms |
3020 KB |
Output is correct |
8 |
Correct |
29 ms |
7136 KB |
Output is correct |
9 |
Correct |
33 ms |
8996 KB |
Output is correct |
10 |
Correct |
3 ms |
3020 KB |
Output is correct |
11 |
Correct |
47 ms |
10820 KB |
Output is correct |
12 |
Correct |
55 ms |
12968 KB |
Output is correct |
13 |
Correct |
3 ms |
3148 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3020 KB |
Output is correct |
2 |
Correct |
3 ms |
3020 KB |
Output is correct |
3 |
Incorrect |
2 ms |
3020 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
65 ms |
15324 KB |
Output is correct |
2 |
Correct |
51 ms |
15280 KB |
Output is correct |
3 |
Correct |
36 ms |
11132 KB |
Output is correct |
4 |
Correct |
9 ms |
4864 KB |
Output is correct |
5 |
Correct |
8 ms |
3916 KB |
Output is correct |
6 |
Correct |
14 ms |
5708 KB |
Output is correct |
7 |
Correct |
2 ms |
3020 KB |
Output is correct |
8 |
Correct |
29 ms |
7136 KB |
Output is correct |
9 |
Correct |
33 ms |
8996 KB |
Output is correct |
10 |
Correct |
3 ms |
3020 KB |
Output is correct |
11 |
Correct |
47 ms |
10820 KB |
Output is correct |
12 |
Correct |
55 ms |
12968 KB |
Output is correct |
13 |
Correct |
3 ms |
3148 KB |
Output is correct |
14 |
Correct |
2 ms |
3020 KB |
Output is correct |
15 |
Correct |
3 ms |
3020 KB |
Output is correct |
16 |
Incorrect |
2 ms |
3020 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
6084 KB |
Output is correct |
2 |
Correct |
24 ms |
6124 KB |
Output is correct |
3 |
Correct |
24 ms |
6112 KB |
Output is correct |
4 |
Correct |
25 ms |
6140 KB |
Output is correct |
5 |
Correct |
23 ms |
6124 KB |
Output is correct |
6 |
Correct |
26 ms |
6512 KB |
Output is correct |
7 |
Correct |
30 ms |
6236 KB |
Output is correct |
8 |
Correct |
28 ms |
6184 KB |
Output is correct |
9 |
Correct |
24 ms |
6024 KB |
Output is correct |
10 |
Correct |
26 ms |
6220 KB |
Output is correct |
11 |
Correct |
3 ms |
3036 KB |
Output is correct |
12 |
Correct |
6 ms |
3672 KB |
Output is correct |
13 |
Correct |
6 ms |
3656 KB |
Output is correct |
14 |
Correct |
6 ms |
3680 KB |
Output is correct |
15 |
Correct |
6 ms |
3656 KB |
Output is correct |
16 |
Correct |
6 ms |
3676 KB |
Output is correct |
17 |
Correct |
6 ms |
3656 KB |
Output is correct |
18 |
Correct |
6 ms |
3656 KB |
Output is correct |
19 |
Correct |
6 ms |
3656 KB |
Output is correct |
20 |
Correct |
3 ms |
3020 KB |
Output is correct |
21 |
Correct |
3 ms |
3044 KB |
Output is correct |
22 |
Correct |
3 ms |
3020 KB |
Output is correct |
23 |
Correct |
6 ms |
3656 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3020 KB |
Output is correct |
2 |
Correct |
3 ms |
3020 KB |
Output is correct |
3 |
Incorrect |
2 ms |
3020 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
65 ms |
15324 KB |
Output is correct |
2 |
Correct |
51 ms |
15280 KB |
Output is correct |
3 |
Correct |
36 ms |
11132 KB |
Output is correct |
4 |
Correct |
9 ms |
4864 KB |
Output is correct |
5 |
Correct |
8 ms |
3916 KB |
Output is correct |
6 |
Correct |
14 ms |
5708 KB |
Output is correct |
7 |
Correct |
2 ms |
3020 KB |
Output is correct |
8 |
Correct |
29 ms |
7136 KB |
Output is correct |
9 |
Correct |
33 ms |
8996 KB |
Output is correct |
10 |
Correct |
3 ms |
3020 KB |
Output is correct |
11 |
Correct |
47 ms |
10820 KB |
Output is correct |
12 |
Correct |
55 ms |
12968 KB |
Output is correct |
13 |
Correct |
3 ms |
3148 KB |
Output is correct |
14 |
Correct |
2 ms |
3020 KB |
Output is correct |
15 |
Correct |
3 ms |
3020 KB |
Output is correct |
16 |
Incorrect |
2 ms |
3020 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |