//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include"dreaming.h"
#include <bits/stdc++.h>
//#define int long long
#define ll long long
#define fi first
#define se second
#define pb push_back
#define all(lmao) lmao.begin(), lmao.end()
using namespace std;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tp;
const int N = 3e5 + 5;
//const int oo = 1e18;
//const int mod = 1e9 + 7;
int n, m, l, mx, d[5][N], tmp, vr, dk, k, e;
vector<pii> p[N];
bool fl[N];
void dfs(int t, int u,int v){
if(d[t][u] > d[t][mx]) mx = u;
for(auto [j, w] : p[u]){
if(j == v) continue;
d[t][j] = d[t][u] + w;
dfs(t, j, u);
}
}
void sol(int u,int v){
if(d[1][u] + d[2][u] == dk && max(d[1][u], d[2][u]) < tmp){
tmp = max(d[1][u], d[2][u]);
}
fl[u] = true;
for(auto [j, w] : p[u]){
if(j == v) continue;
sol(j, u);
}
}
int travelTime(int NT,int M,int L, int A[],int B[],int T[]){
n = NT, m = M, l = L;
for(int i = 0; i < m; i ++){
A[i]++;
B[i]++;
p[A[i]].pb({B[i], T[i]});
p[B[i]].pb({A[i], T[i]});
}
vector<int> c;
for(int i = 1; i <= n; i ++){
if(!fl[i]){
mx = 0;
dfs(0, i, 0);
k = mx;
mx = 0;
dfs(1, k, 0);
dk = d[1][mx];
e = mx;
dfs(2, e, 0);
tmp = 1e9;
sol(k, 0);
c.pb(tmp);
}
}
sort(all(c), greater<int>());
int ans = 0;
tmp = 0;
for(int i = 1; i <= c.size() - 1; i ++){
ans = max({ans, c[0] + c[i] + l, tmp + l + c[i]});
tmp = max(tmp, l + c[i]);
}
return ans;
}
//#define LOCAL
#ifdef LOCAL
int A[N], B[N], T[N], NT, M, L;
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define task "v"
if(fopen(task ".inp","r")){
freopen(task ".inp","r",stdin);
freopen(task ".out","w",stdout);
}
cin >> NT >> M >> L;
for(int i = 0; i < M; i ++){
cin >> A[i] >> B[i] >> T[i];
}
cout << travelTime(NT, M, L, A, B, T) << "\n";
}
#endif // LOCAL
Compilation message
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:73:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
73 | for(int i = 1; i <= c.size() - 1; i ++){
| ~~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
36 ms |
21328 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
10584 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
36 ms |
21328 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
13592 KB |
Output is correct |
2 |
Correct |
16 ms |
13532 KB |
Output is correct |
3 |
Correct |
16 ms |
13404 KB |
Output is correct |
4 |
Correct |
29 ms |
13496 KB |
Output is correct |
5 |
Correct |
16 ms |
13532 KB |
Output is correct |
6 |
Correct |
17 ms |
14048 KB |
Output is correct |
7 |
Correct |
17 ms |
13660 KB |
Output is correct |
8 |
Correct |
15 ms |
13400 KB |
Output is correct |
9 |
Correct |
15 ms |
13404 KB |
Output is correct |
10 |
Correct |
18 ms |
13784 KB |
Output is correct |
11 |
Correct |
2 ms |
10588 KB |
Output is correct |
12 |
Correct |
5 ms |
11480 KB |
Output is correct |
13 |
Correct |
5 ms |
11732 KB |
Output is correct |
14 |
Correct |
7 ms |
11480 KB |
Output is correct |
15 |
Correct |
6 ms |
11476 KB |
Output is correct |
16 |
Correct |
5 ms |
11480 KB |
Output is correct |
17 |
Correct |
5 ms |
11480 KB |
Output is correct |
18 |
Correct |
5 ms |
11736 KB |
Output is correct |
19 |
Correct |
6 ms |
11476 KB |
Output is correct |
20 |
Correct |
2 ms |
10584 KB |
Output is correct |
21 |
Correct |
3 ms |
10584 KB |
Output is correct |
22 |
Correct |
2 ms |
10588 KB |
Output is correct |
23 |
Correct |
5 ms |
11572 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
10584 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
36 ms |
21328 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |