#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;
vector<vector<pair<int,int>>> gri;
vector<int> dis = {0,0};
vector<int> dep;
vector<int> used;
int jic = 0;
int ans = 0;
int y;
int dfs2(int x, int p, int d){
used[x] = 1;
int bes = 0;
int bes2 = 0;
for(int i = 0; i < gri[x].size(); ++i){
if(gri[x][i].first == p)continue;
int cur = dfs2(gri[x][i].first, x, d+gri[x][i].second);
if(bes < cur)swap(cur, bes);
if(bes2 < cur)swap(cur, bes2);
}
ans = max(ans, max(bes+bes2-2*d, d));
dep.push_back(max(bes,d));
return max(d, bes);
}
void find(int ind){
if(!gri[ind].size()){dis.push_back(0);return;}
dep.clear();
y = dfs2(ind,ind,0);
jic = max(jic,y);
sort(dep.begin(),dep.end());
dis.push_back(dep[0]);
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
used.resize(N,0);
gri.resize(N);
for(int i = 0; i < M; ++i){
gri[A[i]].push_back({B[i],T[i]});
gri[B[i]].push_back({A[i],T[i]});
}
for(int i = 0; i < N; ++i){
if(!used[i] && gri[i].size() == 1){
find(i);
}
}
sort(dis.rbegin(),dis.rend());
return max(jic,dis[0]+L+dis[1]);
}
Compilation message
dreaming.cpp: In function 'int dfs2(int, int, int)':
dreaming.cpp:17:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
17 | for(int i = 0; i < gri[x].size(); ++i){
| ~~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
60 ms |
14584 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
60 ms |
14584 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
60 ms |
14584 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
38 ms |
5504 KB |
Output is correct |
2 |
Incorrect |
30 ms |
5504 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
60 ms |
14584 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
60 ms |
14584 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |