#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;
// 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], dis[NMAX], vv[NMAX];
int maksd,poc;
vector<int>vis,nes;
set<int>vektor;
void izr() {
for (auto u : vis) {
u = dis[u];
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]) {
return;
}
vis.pb(node);
visited[node] =1;
dis[node] = max(dis[node], dist);
if ( dist > maksd ) {
maksd = dist;
poc = node;
}
for (auto u : al[node] ) {
dfs2(u.fi, u.se + dist);
}
}
void clrvis() {
for (auto u : vis) {
visited[u] = 0;
}
vis.clear();
}
void clrdis() {
for (auto u : vis) {
dis[u] = 0;
}
}
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();
int poc1 = poc;
maksd = -1;
dfs1(poc);
clrdis();
clrvis();
int poc2 = poc;
D = maksd;
dfs2(poc1);
clrvis();
dfs2(poc2);
maks = INT_MAX;
izr();
clrdis();
//cout << D << ' ' << maks << endl;
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()-3] + l);
return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
69 ms |
57036 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
21 ms |
47240 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
69 ms |
57036 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
43 ms |
51080 KB |
Output is correct |
2 |
Correct |
46 ms |
51076 KB |
Output is correct |
3 |
Correct |
46 ms |
51084 KB |
Output is correct |
4 |
Correct |
51 ms |
51072 KB |
Output is correct |
5 |
Correct |
53 ms |
51048 KB |
Output is correct |
6 |
Correct |
46 ms |
51580 KB |
Output is correct |
7 |
Correct |
44 ms |
51236 KB |
Output is correct |
8 |
Correct |
43 ms |
50980 KB |
Output is correct |
9 |
Correct |
46 ms |
51004 KB |
Output is correct |
10 |
Correct |
45 ms |
51160 KB |
Output is correct |
11 |
Correct |
26 ms |
47204 KB |
Output is correct |
12 |
Correct |
32 ms |
49040 KB |
Output is correct |
13 |
Correct |
30 ms |
49116 KB |
Output is correct |
14 |
Correct |
32 ms |
49080 KB |
Output is correct |
15 |
Correct |
31 ms |
49140 KB |
Output is correct |
16 |
Correct |
29 ms |
49232 KB |
Output is correct |
17 |
Correct |
31 ms |
48972 KB |
Output is correct |
18 |
Correct |
36 ms |
49072 KB |
Output is correct |
19 |
Correct |
30 ms |
49008 KB |
Output is correct |
20 |
Correct |
22 ms |
47300 KB |
Output is correct |
21 |
Correct |
25 ms |
47256 KB |
Output is correct |
22 |
Correct |
23 ms |
47316 KB |
Output is correct |
23 |
Correct |
30 ms |
49096 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
21 ms |
47240 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
69 ms |
57036 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |