#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;
struct Edge {
int to, w;
bool operator<(const Edge& other) const {
return w < other.w;
}
};
const int maxN = 1e5 + 5;
const int INF = 1e9 + 5;
vector<Edge> adj[maxN];
vector<int> comp[maxN];
vector<int> curr;
int ccs = 0;
bool vis[maxN];
int dist[maxN];
void dfs(int v) {
vis[v] = true;
comp[ccs].push_back(v);
for(Edge u : adj[v]) {
if (!vis[u.to]) {
dfs(u.to);
}
}
}
pair<int, int> mx(int from, int idx) {
priority_queue<Edge> q;
q.push({from, 0});
for(int i : comp[idx]) {
dist[i] = INF;
}
dist[from] = 0;
while(!q.empty()) {
Edge v = q.top();
q.pop();
if (v.w > dist[v.to]) continue;
for(Edge u : adj[v.to]) {
int d = dist[v.to] + u.w;
if (d < dist[u.to]) {
dist[u.to] = d;
q.push({u.to, dist[u.to]});
}
}
}
pair<int, int> ret = {-1, -1};
for(int i : comp[idx]) {
// cout << i << " " << dist[i] << "\n";
if (dist[i] > ret.second) {
ret = {i, dist[i]};
}
}
assert(ret.second != -1);
assert(ret.second != INF);
return ret;
}
int diameter(int idx) {
int ans = INF;
for(int i : comp[idx]) {
ans = min(ans, mx(i, idx).second);
}
return ans;
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
for(int i = 0; i < M; i++) {
adj[A[i]].push_back({B[i], T[i]});
adj[B[i]].push_back({A[i], T[i]});
}
int sum = 0;
for(int i = 0; i < N; i++) {
if (!vis[i]) {
dfs(i);
sum += diameter(ccs);
ccs++;
}
}
sum += L;
return sum;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1090 ms |
12128 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
4940 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1090 ms |
12128 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
39 ms |
9740 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
4940 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1090 ms |
12128 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |