#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, vi & dist1, vi & dist2, vvpii & G, vi & diam) {
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();
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[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, dist1, dist2, diam;
dist1.assign(N, 1e9);
dist2.assign(N, 1e9);
diam.clear();
ecc.clear();
for (int i = 0; i < N; i++) {
if (dist1[i] == 1e9)
ecc.push_back(calcDist(i, N, dist1, dist2, G, diam));
}
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 |
50 ms |
7788 KB |
Output is correct |
2 |
Correct |
53 ms |
7792 KB |
Output is correct |
3 |
Correct |
32 ms |
5100 KB |
Output is correct |
4 |
Correct |
7 ms |
1388 KB |
Output is correct |
5 |
Incorrect |
6 ms |
1132 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
50 ms |
7788 KB |
Output is correct |
2 |
Correct |
53 ms |
7792 KB |
Output is correct |
3 |
Correct |
32 ms |
5100 KB |
Output is correct |
4 |
Correct |
7 ms |
1388 KB |
Output is correct |
5 |
Incorrect |
6 ms |
1132 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
50 ms |
7788 KB |
Output is correct |
2 |
Correct |
53 ms |
7792 KB |
Output is correct |
3 |
Correct |
32 ms |
5100 KB |
Output is correct |
4 |
Correct |
7 ms |
1388 KB |
Output is correct |
5 |
Incorrect |
6 ms |
1132 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1090 ms |
6248 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
50 ms |
7788 KB |
Output is correct |
2 |
Correct |
53 ms |
7792 KB |
Output is correct |
3 |
Correct |
32 ms |
5100 KB |
Output is correct |
4 |
Correct |
7 ms |
1388 KB |
Output is correct |
5 |
Incorrect |
6 ms |
1132 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
50 ms |
7788 KB |
Output is correct |
2 |
Correct |
53 ms |
7792 KB |
Output is correct |
3 |
Correct |
32 ms |
5100 KB |
Output is correct |
4 |
Correct |
7 ms |
1388 KB |
Output is correct |
5 |
Incorrect |
6 ms |
1132 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |