이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "dreaming.h"
#include <bits/stdc++.h>
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define chkmin(a, b) a = min(a, b)
#define chkmax(a, b) a = max(a, b)
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vii;
const int MAX_N = 1e5 + 5;
vii tree[MAX_N];
int deg[MAX_N];
bitset<MAX_N> visited;
pii DfsFar(int node, int parent, int d) {
visited[node] = true;
pii p = {d, node};
for (auto [neighbor, w] : tree[node]) {
if (neighbor != parent) {
chkmax(p, DfsFar(neighbor, node, d + w));
}
}
return p;
}
bool DfsPath(int node, int parent, int end, vii &path) {
if (node == end) {
path.push_back({node, 0});
return true;
}
for (auto [neighbor, w] : tree[node]) {
if (neighbor != parent && DfsPath(neighbor, node, end, path)) {
path.push_back({node, w});
return true;
}
}
}
int ans = 0;
int FindRadius(int node) {
int v = DfsFar(node, -1, 0).y;
auto [diameter, u] = DfsFar(v, -1, 0);
int x = diameter;
int dist = 0;
vii path;
DfsPath(v, -1, u, path);
for (auto [node, w] : path) {
chkmin(x, max(dist, diameter - dist));
dist += w;
}
chkmax(ans, diameter);
return x;
}
int travelTime(int n, int m, int l, int a[], int b[], int t[]) {
for (int i = 0; i < m; i++) {
deg[a[i]]++, deg[b[i]]++;
}
for (int i = 0; i < n; i++) {
tree[i].reserve(deg[i]);
}
for (int i = 0; i < m; i++) {
tree[a[i]].push_back({b[i], t[i]});
tree[b[i]].push_back({a[i], t[i]});
}
int s = 0;
for (int i = 0; i < n; i++) {
if (!visited[i]) {
s += FindRadius(i) + l;
}
}
chkmax(ans, s - l);
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
dreaming.cpp: In function 'bool DfsPath(int, int, int, vii&)':
dreaming.cpp:44:1: warning: control reaches end of non-void function [-Wreturn-type]
44 | }
| ^
# | 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... |