#include <bits/stdc++.h>
#include "dreaming.h"
#define FAST {ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
#define FILES {freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);}
#define ll long long
#define ull unsigned long long
#define pqueue priority_queue
#define pb push_back
#define fi first
#define se second
#define ld long double
#define pii pair<int,int>
#define pll pair<long long,long long>
#define all(a) (a).begin(), (a).end()
#define mp make_pair
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<pll, null_type,less<pll>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key -> # less than k
// find_by_order -> k-th element
// pq max element
const double eps = 0.00000001;
const int NMAX = 2000010;
const ll inf = LLONG_MAX/3;
const ll modi = 998244353;
int D, maks, mx;
vector<pii>al[NMAX];
int visited[NMAX], vv[NMAX];
int maksd,poc;
vector<int>vis,nes;
set<int>vektor;
void izr() {
for (auto u : nes) {
maks = min(maks, max(u,D-u));
}
}
void dfs1(int node, int dist = 0) {
if (visited[node]) {
return;
}
vv[node] = 1;
vis.pb(node);
visited[node] =1;
if ( dist > maksd ) {
maksd = dist;
poc = node;
}
for (auto u : al[node] ) {
dfs1(u.fi, u.se + dist);
}
}
void dfs2(int node, int dist = 0) {
if (visited[node]||maks!= INT_MAX) {
return;
}
vis.pb(node);
visited[node] =1;
nes.pb(dist);
if ( dist == maksd ) {
izr();
return;
}
if ( dist > maksd ) {
maksd = dist;
poc = node;
}
for (auto u : al[node] ) {
dfs2(u.fi, u.se + dist);
}
nes.erase(nes.end()-1);
}
void clrvis() {
for (auto u : vis) {
visited[u] = 0;
}
vis.clear();
}
int travelTime(int n,int m,int l,int A[],int B[],int T[]) {
for (int i = 0 ; i < m; i++) {
al[A[i]].pb({B[i],T[i]});
al[B[i]].pb({A[i],T[i]});
}
vector<int>r;
for (int i = 0 ; i < n ; i++ ) {
if (!vv[i]) {
maksd = -1;
dfs1(i);
clrvis();
maksd = -1;
dfs1(poc);
clrvis();
maks = INT_MAX;
D = maksd;
dfs2(poc);
clrvis();
nes.clear();
r.pb(maks);
}
}
//for (auto u : r) cout << u << ' ';
sort(all(r));
int res = r[r.size()-1];
if ( r.size() == 1 ) {
return res;
}
if ( r.size() == 2 ) {
return res + r[0] + l;
}
res = max(res, res + r[r.size()-2] + l);
res = max(res , r[r.size()-2] + l + r[r.size()-2] + l);
return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
68 ms |
58540 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
28 ms |
47192 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
68 ms |
58540 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
46 ms |
51068 KB |
Output is correct |
2 |
Incorrect |
43 ms |
51116 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
28 ms |
47192 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
68 ms |
58540 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |