#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include "dreaming.h"
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;
int calcDist(int i, int N, vvpii & G, vi & diam, vector<bool> & visited) {
vector<int> dist1, dist2;
dist1.assign(N, 1e9);
dist1[i] = 0;
queue<int> Q;
Q.push(i);
int u, v, t, maxNode = i;
vi CC = {};
while(!Q.empty()) {
u = Q.front();
Q.pop();
visited[u] = true;
CC.push_back(u);
if (dist1[u] > dist1[maxNode])
maxNode = u;
for (auto connection: G[u]) {
v = connection.first;
t = connection.second;
if (dist1[v] > dist1[u] + t) {
dist1[v] = dist1[u] + t;
Q.push(v);
}
}
}
dist2.assign(N, 1e9);
dist2[maxNode] = 0;
Q.push(maxNode);
int curDiameter = 0;
while(!Q.empty()) {
u = Q.front();
curDiameter = max(curDiameter, dist2[u]);
Q.pop();
for (auto connection: G[u]) {
v = connection.first;
t = connection.second;
if (dist2[v] > dist2[u] + t) {
dist2[v] = dist2[u] + t;
Q.push(v);
}
}
}
diam.push_back(curDiameter);
int ecc = 1e9;
for (auto node: CC)
ecc = min(ecc, max(dist1[node], dist2[node]));
return ecc;
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
vvpii G;
G.assign(N, vpii());
for (int i = 0; i < M; i++) {
G[A[i]].push_back(make_pair(B[i], T[i]));
G[B[i]].push_back(make_pair(A[i], T[i]));
}
vi ecc, diam;
vector<bool> visited(N, false);
diam.clear();
ecc.clear();
for (int i = 0; i < N; i++) {
if (!visited[i])
ecc.push_back(calcDist(i, N, G, diam, visited));
}
sort(ecc.begin(), ecc.end(), greater<int>());
int CC = (int) ecc.size();
int ans = diam[0];
for (int i = 1; i < CC; i++) {
ans = max(ans, ecc[0]+ecc[i]+L);
}
for (int i = 1; i < CC; i++) {
for (int j = 2; j < CC; j++) {
ans = max(ans, ecc[i]+ecc[j]+2*L);
}
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
55 ms |
8812 KB |
Output is correct |
2 |
Correct |
50 ms |
8828 KB |
Output is correct |
3 |
Correct |
33 ms |
6120 KB |
Output is correct |
4 |
Correct |
7 ms |
1644 KB |
Output is correct |
5 |
Incorrect |
6 ms |
1260 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
55 ms |
8812 KB |
Output is correct |
2 |
Correct |
50 ms |
8828 KB |
Output is correct |
3 |
Correct |
33 ms |
6120 KB |
Output is correct |
4 |
Correct |
7 ms |
1644 KB |
Output is correct |
5 |
Incorrect |
6 ms |
1260 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
55 ms |
8812 KB |
Output is correct |
2 |
Correct |
50 ms |
8828 KB |
Output is correct |
3 |
Correct |
33 ms |
6120 KB |
Output is correct |
4 |
Correct |
7 ms |
1644 KB |
Output is correct |
5 |
Incorrect |
6 ms |
1260 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1083 ms |
6312 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
55 ms |
8812 KB |
Output is correct |
2 |
Correct |
50 ms |
8828 KB |
Output is correct |
3 |
Correct |
33 ms |
6120 KB |
Output is correct |
4 |
Correct |
7 ms |
1644 KB |
Output is correct |
5 |
Incorrect |
6 ms |
1260 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
55 ms |
8812 KB |
Output is correct |
2 |
Correct |
50 ms |
8828 KB |
Output is correct |
3 |
Correct |
33 ms |
6120 KB |
Output is correct |
4 |
Correct |
7 ms |
1644 KB |
Output is correct |
5 |
Incorrect |
6 ms |
1260 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |