#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
vector<vector<pair<int,int>>> arr(N);
for (int i = 0; i < M; i++){
arr[A[i]].push_back({B[i],T[i]});
arr[B[i]].push_back({A[i],T[i]});
}
vector<int> dp(N,-1);
function<int(int)> f = [&](int src)->int{
queue<array<int,3>> qu;
qu.push({src,0,-1});
int manode = src;
int mm = 0;
vector<int> gez;
while (qu.size()){
int node = qu.front()[0];
int w = qu.front()[1];
int lnode = qu.front()[2];
qu.pop();
if (w>mm) manode=node,mm=w;
for (auto nex : arr[node]){
if (nex.first==lnode) continue;
qu.push({nex.first,nex.second+w,node});
}
}
qu.push({manode,0,-1});
while (qu.size()){
int node = qu.front()[0];
int w = qu.front()[1];
int lnode = qu.front()[2];
qu.pop();
dp[node]=w;
if (dp[node]>dp[manode]) manode=node;
for (auto nex : arr[node]){
if (nex.first==lnode) continue;
qu.push({nex.first,nex.second+w,node});
}
}
int ret = dp[manode];
qu.push({manode,0,-1});
while (qu.size()){
int node = qu.front()[0];
int w = qu.front()[1];
int lnode = qu.front()[2];
qu.pop();
ret=min(ret,max(dp[node],w));
for (auto &nex : arr[node]){
if (nex.first==lnode) continue;
qu.push({nex.first,nex.second+w,node});
}
}
return ret;
};
vector<int> ansarr;
for (int i = 0; i < N; ++i)
{
if (dp[i]==-1) {
ansarr.push_back(f(i));
}
}
if (ansarr.size()==1) return 0;
sort(ansarr.begin(), ansarr.end());
for (int i = 0; i < ansarr.size()-1; i++){
ansarr[i]+=L;
}
sort(ansarr.begin(), ansarr.end());
return ansarr[ansarr.size()-1]+ansarr[ansarr.size()-2];
}
Compilation message
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:65:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
65 | for (int i = 0; i < ansarr.size()-1; i++){
| ~~^~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
30 ms |
8272 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
30 ms |
8272 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
6108 KB |
Output is correct |
2 |
Correct |
21 ms |
6096 KB |
Output is correct |
3 |
Correct |
25 ms |
6360 KB |
Output is correct |
4 |
Correct |
20 ms |
6108 KB |
Output is correct |
5 |
Correct |
20 ms |
6108 KB |
Output is correct |
6 |
Correct |
22 ms |
6624 KB |
Output is correct |
7 |
Correct |
23 ms |
6284 KB |
Output is correct |
8 |
Correct |
21 ms |
5992 KB |
Output is correct |
9 |
Correct |
21 ms |
5980 KB |
Output is correct |
10 |
Correct |
20 ms |
6488 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
10 ms |
3840 KB |
Output is correct |
13 |
Correct |
13 ms |
4052 KB |
Output is correct |
14 |
Correct |
10 ms |
3664 KB |
Output is correct |
15 |
Correct |
10 ms |
3800 KB |
Output is correct |
16 |
Correct |
11 ms |
3800 KB |
Output is correct |
17 |
Correct |
11 ms |
3632 KB |
Output is correct |
18 |
Correct |
11 ms |
3800 KB |
Output is correct |
19 |
Correct |
11 ms |
3800 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
10 ms |
3800 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
30 ms |
8272 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |