This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int MN = 1e5 + 5;
vector<pii> g[MN];
int rt, D, R, dis[MN];
bool vis[MN];
void dfs(int u, int p, int d, bool qu) {
vis[u] = true;
if (d >= D) D = d, rt = u;
if (qu) R = min(R, max(d, dis[u]));
else dis[u] = d;
for (pii e : g[u]) if (e.first != p) {
dfs(e.first, u, d + e.second, qu);
}
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
for (int i = 0; i < M; i++) {
int u = A[i], v = B[i], w = T[i];
g[u].emplace_back(v, w);
g[v].emplace_back(u, w);
}
vector<pii> lens;
for (int i = 0; i < N; i++) {
if (!vis[i]) {
D = 0, R = INT_MAX;
dfs(i, -1, 0, 0);
dfs(rt, -1, 0, 0);
dfs(rt, -1, 0, 1);
lens.emplace_back(R, D);
}
}
sort(lens.rbegin(), lens.rend());
int mn = lens[0].second;
if (lens.size() >= 2) mn = max(mn, lens[0].first + L + lens[1].first);
if (lens.size() >= 3) mn = max(mn, lens[1].first + 2 * L + lens[2].first);
return mn;
}
/*
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
int a[] = {0,8,2,5,5,1,1,10};
int b[] = {8,2,7,11,1,3,9,6};
int c[] = {4,2,4,3,7,1,5,3};
cout << travelTime(12,8,2,a,b,c) << '\n';
return 0;
}
*/
# | 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... |