#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);
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 ans = 0;
for (auto d: diam)
ans = max(ans, d);
for (int i = 1; i < (int) ecc.size(); i++)
ans = max(ans, ecc[0]+ecc[i]+L);
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
49 ms |
9068 KB |
Output is correct |
2 |
Correct |
63 ms |
8944 KB |
Output is correct |
3 |
Correct |
32 ms |
6124 KB |
Output is correct |
4 |
Correct |
7 ms |
1644 KB |
Output is correct |
5 |
Correct |
6 ms |
1388 KB |
Output is correct |
6 |
Correct |
12 ms |
2284 KB |
Output is correct |
7 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
49 ms |
9068 KB |
Output is correct |
2 |
Correct |
63 ms |
8944 KB |
Output is correct |
3 |
Correct |
32 ms |
6124 KB |
Output is correct |
4 |
Correct |
7 ms |
1644 KB |
Output is correct |
5 |
Correct |
6 ms |
1388 KB |
Output is correct |
6 |
Correct |
12 ms |
2284 KB |
Output is correct |
7 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
49 ms |
9068 KB |
Output is correct |
2 |
Correct |
63 ms |
8944 KB |
Output is correct |
3 |
Correct |
32 ms |
6124 KB |
Output is correct |
4 |
Correct |
7 ms |
1644 KB |
Output is correct |
5 |
Correct |
6 ms |
1388 KB |
Output is correct |
6 |
Correct |
12 ms |
2284 KB |
Output is correct |
7 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
35 ms |
6760 KB |
Output is correct |
2 |
Incorrect |
34 ms |
6760 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
49 ms |
9068 KB |
Output is correct |
2 |
Correct |
63 ms |
8944 KB |
Output is correct |
3 |
Correct |
32 ms |
6124 KB |
Output is correct |
4 |
Correct |
7 ms |
1644 KB |
Output is correct |
5 |
Correct |
6 ms |
1388 KB |
Output is correct |
6 |
Correct |
12 ms |
2284 KB |
Output is correct |
7 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
49 ms |
9068 KB |
Output is correct |
2 |
Correct |
63 ms |
8944 KB |
Output is correct |
3 |
Correct |
32 ms |
6124 KB |
Output is correct |
4 |
Correct |
7 ms |
1644 KB |
Output is correct |
5 |
Correct |
6 ms |
1388 KB |
Output is correct |
6 |
Correct |
12 ms |
2284 KB |
Output is correct |
7 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |