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<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define vi vector<int>
#define vvi vector<vi>
#define pi pair<int, int>
#define F first
#define S second
#define vp vector<pi>
#define vvp vector<vp>
vi V;
vvp Adj;
struct point {
int p = -1;
int t = -1;
int c = -1;
};
point oinkoink(int p, int dfp, int t) {
if (Adj[p].size() == 0) return {p, 0, 0};
if (Adj[p].size() == 1 && Adj[p][0].F == dfp) return {p, t, -1};
point m;
for (auto i : Adj[p]) {
if (i.F == dfp) continue;
point a = oinkoink(i.F, p, t+i.S);
if (m.t >= a.t) continue;
m = a;
if (m.t > t*2 && m.c == -1) m.c = min(t+i.S, m.t-t+i.S);
}
return m;
}
pi oink(int p, int n) {
int a = oinkoink(p, -1, 0).p;
point k = oinkoink(a, -1, 0);
return {k.c, k.t};
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
Adj.clear();
Adj.resize(N);
V.clear();
V.resize(N, 0);
int a, b, c, d;
for (int i = 0; i < M; i++) {
int a = A[i], b = B[i], t = T[i];
Adj[a].push_back({b, t});
Adj[b].push_back({a, t});
}
for (int i = 0; i < N; i++) {
if (V[i]) continue;
pi on = oink(i, N);
int o = on.F;
int d = max(d, on.S);
if (o > a) {c = b; b = a; a = o; continue;}
if (o > b) {c = b; b = o; continue;}
if (o > c) {c = o; continue;}
}
int maks = d;
maks = max(maks, a+b+L);
maks = max(maks, b+L+L+c);
return maks;
}
Compilation message (stderr)
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:50:18: warning: 'd' is used uninitialized in this function [-Wuninitialized]
50 | int a, b, c, d;
| ^
dreaming.cpp:67:27: warning: 'c' may be used uninitialized in this function [-Wmaybe-uninitialized]
67 | maks = max(maks, b+L+L+c);
| ~~~~~^~
dreaming.cpp:67:23: warning: 'b' may be used uninitialized in this function [-Wmaybe-uninitialized]
67 | maks = max(maks, b+L+L+c);
| ~^~
dreaming.cpp:66:23: warning: 'a' may be used uninitialized in this function [-Wmaybe-uninitialized]
66 | maks = max(maks, a+b+L);
| ~^~
# | 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... |