#include "dreaming.h"
#include <algorithm>
#include <iostream>
#include <queue>
#include <utility>
#include <vector>
#include <map>
using namespace std;
#define pb push_back
int h;
map<pair<int, int>, int> weight;
vector<int> adj[1000000];
vector<bool> vis(1000000);
vector<int> par(1000000);
int maxdist;
vector<int> component;
void dfs(int node, int dist) {
vis[node] = 1;
component.pb(node);
if(dist > maxdist) {
maxdist = dist;
h = node;
}
for(auto j : adj[node]) {
if(!vis[j]) {
par[j] = node;
dfs(j, dist+weight[{node, j}]);
}
}
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
for(int i = 0; i<M; i++) {
adj[A[i]].pb(B[i]);
adj[B[i]].pb(A[i]);
weight[{A[i], B[i]}] = T[i];
weight[{B[i], A[i]}] = T[i];
}
vector<int> all;
for(int i = 0; i<N; i++) {
if(!vis[i]) {
// cout << i << " ";
h = i;
maxdist = 0;
component.clear();
dfs(i, 0);
for(auto j : component) {
par[j] = 0;
vis[j] = 0;
}
maxdist = 0;
int x = h;
dfs(x, 0);
vector<int> path;
int tt = 0;
while(h != x) {
path.pb(weight[{h, par[h]}]);
tt += weight[{h, par[h]}];
h = par[h];
}
int y = 1000000000;
h = 0;
for(int j = 0; j<path.size(); j++) {
h += path[j];
y = min(y, max(h, tt-h));
}
// cout << y << "\n";
if(y==1000000000) {
all.pb(0);
}
else all.pb(y);
}
}
sort(all.rbegin(), all.rend());
// for(auto j : all) cout << j << " ";
return all[0] + all[1] + L;
}
// int32_t main() {
// ios::sync_with_stdio(false);
// cout.tie(0); cin.tie(0);
// int n, m, l;
// cin >> n >> m >> l;
// int A[m], B[m], C[m];
// for(int i = 0; i<m; i++) {
// cin >> A[i] >> B[i] >> C[i];
// }
// cout << travelTime(n, m, l, A, B, C);
// return 0;
// }
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |