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 <vector>
#include <algorithm>
#include <cassert>
#include <iostream>
#include <cstdlib>
using namespace std;
typedef vector<int> VI;
typedef long long llong;
bool is_subtask4(int N, int M, int A[], int B[], int T[], VI& deg) {
deg.assign(N, 0);
for (int j = 0; j < M; ++j) {
int u = A[j], v = B[j];
++deg[u];
++deg[v];
}
for (int u = 0; u < N; ++u)
if (deg[u] > 1)
return false;
return true;
}
const llong INF = 1e18;
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
VI deg(N);
if (is_subtask4(N, M, A, B, T, deg)) {
if (N == 1)
return 0;
if (N == 2)
return M == 0 ? L : T[0];
if (M == 0)
return 2*L;
if (M == 1)
return T[0] + L;
// cerr << "N:" << N << " M:" << M << " L:" << L << endl;
sort(T, T+M, greater<int>());
llong res = T[0] + L + T[1];
for (int j = 2; j < M; ++j) {
res = max(res, (llong) T[j] + L + L + T[1]);
}
if (M < N-1) {
res = max(res, (llong) L + L + T[1]);
}
return res;
}
assert(false);
return 1 + rand();
}
# | 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... |