이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "dreaming.h"
#include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
using namespace std;
vector<vector<pair<int, int> > > G;
vector<bool> vis;
ll ans, help = 0;
void dfs(int at, int parent, long long dist, vector<pair<int, long long> >& paths){
vis[at] = true;
paths.push_back(make_pair(at, dist));
for(auto next : G[at]){
if(next.first != parent){
dfs(next.first, at, dist + next.second, paths);
}
}
}
void solve(int start){
vector<pair<int, ll> > d, d2;
dfs(start,start, 0, d);
ll len1 = -1;
int node1;
for(auto t : d){
if(len1 < t.second){
len1 = t.second;
node1 = t.first;
}
}
d.clear();
dfs(node1,node1, 0, d);
ll len2 = -1;
int node2;
map<int,ll> store;
for(auto t : d){
store[t.first] = t.second;
if(len2 < t.second){
len2 = t.second;
node2 = t.first;
}
}
help = max(help, len2);
dfs(node2,node2, 0, d2);
for(auto t : d2){
ans = min(ans, max(t.second, store[t.first]));
}
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
vis.resize(N, false);
G.resize(N);
for(int i = 0; i < M; i++){
G[A[i]].pb(mp(B[i], T[i]));
G[B[i]].pb(mp(A[i], T[i]));
}
vector<ll> arr;
for(int i = 0; i < N; i++){
if(!vis[i]){
ans = 2e9;
solve(i);
arr.pb(ans);
}
else
continue;
}
sort(arr.rbegin(), arr.rend());
if(arr.size() == 1) return max(arr[0], help);
else if(arr.size() == 2)
return max(help, arr[0] + arr[1] + L);
else
return max(max(arr[0] + arr[1] + L, arr[1] + arr[2] + 2 * L), help);
}
컴파일 시 표준 에러 (stderr) 메시지
dreaming.cpp: In function 'void solve(int)':
dreaming.cpp:43:5: warning: 'node2' may be used uninitialized in this function [-Wmaybe-uninitialized]
43 | dfs(node2,node2, 0, d2);
| ~~~^~~~~~~~~~~~~~~~~~~~
dreaming.cpp:31:5: warning: 'node1' may be used uninitialized in this function [-Wmaybe-uninitialized]
31 | dfs(node1,node1, 0, d);
| ~~~^~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |