#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, maxDist = 0, 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;
}
int main() {
return 0;
}
Compilation message
dreaming.cpp: In function 'int calcDist(int, int, vi&, vi&, vvpii&, vi&)':
dreaming.cpp:17:15: warning: unused variable 'maxDist' [-Wunused-variable]
17 | int u, v, t, maxDist = 0, maxNode = i;
| ^~~~~~~
/tmp/cc9rlxnU.o: In function `main':
dreaming.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/cck8Na7K.o:grader.c:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status