#include <bits/stdc++.h>
#pragma GCC optimize("O3")
typedef long long ll;
#define FOR(i,x,y) for(ll i=x; i<y; i++)
#define FORNEG(i,x,y) for(ll i=x; i>y; i--)
#define double long double
#include "dreaming.h"
using namespace std;
ll cc[100005];
ll find(ll a){
while (a!=cc[a]) cc[a] = cc[cc[a]], a = cc[a];
return a;
}
void unite(ll a,ll b){
cc[find(a)] = find(b);
}
ll globalmax = 0;
vector<pair<ll, ll>> edges[100005];
vector<ll> sussies[100005];
int sus(vector<ll> a){
if (a.size()==1) return 0;
bool visited[100005];
FOR(i,0,100004) visited[i] = 0;
vector<vector<ll>> stack;
ll maxi = 0;
vector<ll> path;
stack.push_back({0,a[0]});
visited[a[0]] = 1;
while (stack.size()){
vector<ll> temp;
vector<ll> node = stack[stack.size()-1];
stack.pop_back();
if (maxi < node[0]) path = node, maxi = node[0];
for (auto&i : edges[node[node.size()-1]]){
if (!visited[i.first]){
visited[i.first] = 1;
temp = node;
temp[0] += i.second;
temp.push_back(i.first);
stack.push_back(temp);
}
}
}
ll realsus = path[path.size()-1];
FOR(i,0,100004) visited[i] = 0;
stack.clear();
maxi = 0;
path.clear();
stack.push_back({0,0,realsus});
visited[realsus] = 1;
while (stack.size()){
vector<ll> temp;
vector<ll> node = stack[stack.size()-1];
stack.pop_back();
if (maxi < node[0]) path = node, maxi = node[0];
for (auto&i : edges[node[node.size()-1]]){
if (!visited[i.first]){
visited[i.first] = 1;
temp = node;
temp.pop_back();
temp[0] += i.second;
temp.push_back(i.second);
temp.push_back(i.first);
stack.push_back(temp);
}
}
}
ll mini = 1000000000000;
ll cur = 0;
globalmax = max(globalmax, path[0]);
FOR(i,1,path.size()-1){
cur += path[i];
mini = min(mini, max(path[0]-cur, cur));
}
return mini;
}
int travelTime(int n, int m, int L, int a[], int b[], int t[]){
FOR(i,0,n) cc[i] = i;
FOR(i,0,m){
edges[a[i]].push_back({b[i], t[i]});
edges[b[i]].push_back({a[i], t[i]});
}
FOR(i,0,n){
for (auto&j : edges[i]){
unite(i, j.first);
}
}
FOR(i,0,n){
sussies[find(i)].push_back(i);
}
vector<ll> kindasus;
for (auto&i : sussies){
if (i.size()==0) continue;
kindasus.push_back(sus(i));
}
sort(kindasus.begin(), kindasus.end());
// for (auto&i : kindasus){
// cout << i << endl;
// }
if (kindasus.size() == 1) return globalmax;
if (kindasus.size()==2){
return max(globalmax, kindasus[kindasus.size()-1] + kindasus[kindasus.size()-2] + L);
}
return max(globalmax, max(kindasus[kindasus.size()-2] + kindasus[kindasus.size()-3] + 2*L, kindasus[kindasus.size()-1] + kindasus[kindasus.size()-2] + L));
}
Compilation message
dreaming.cpp: In function 'int sus(std::vector<long long int>)':
dreaming.cpp:4:33: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
4 | #define FOR(i,x,y) for(ll i=x; i<y; i++)
......
106 | FOR(i,1,path.size()-1){
| ~~~~~~~~~~~~~~~~~
dreaming.cpp:106:2: note: in expansion of macro 'FOR'
106 | FOR(i,1,path.size()-1){
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1047 ms |
14784 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5076 KB |
Output is correct |
2 |
Correct |
3 ms |
5076 KB |
Output is correct |
3 |
Correct |
3 ms |
5076 KB |
Output is correct |
4 |
Correct |
3 ms |
5076 KB |
Output is correct |
5 |
Correct |
3 ms |
5076 KB |
Output is correct |
6 |
Correct |
4 ms |
5076 KB |
Output is correct |
7 |
Correct |
3 ms |
5076 KB |
Output is correct |
8 |
Correct |
3 ms |
5076 KB |
Output is correct |
9 |
Correct |
3 ms |
5076 KB |
Output is correct |
10 |
Correct |
3 ms |
5076 KB |
Output is correct |
11 |
Correct |
2 ms |
5076 KB |
Output is correct |
12 |
Correct |
3 ms |
5204 KB |
Output is correct |
13 |
Correct |
3 ms |
5076 KB |
Output is correct |
14 |
Correct |
3 ms |
5076 KB |
Output is correct |
15 |
Correct |
3 ms |
5076 KB |
Output is correct |
16 |
Correct |
3 ms |
5076 KB |
Output is correct |
17 |
Correct |
3 ms |
5076 KB |
Output is correct |
18 |
Correct |
3 ms |
5076 KB |
Output is correct |
19 |
Correct |
3 ms |
5076 KB |
Output is correct |
20 |
Correct |
3 ms |
5076 KB |
Output is correct |
21 |
Correct |
4 ms |
5076 KB |
Output is correct |
22 |
Correct |
3 ms |
5076 KB |
Output is correct |
23 |
Correct |
3 ms |
5076 KB |
Output is correct |
24 |
Correct |
4 ms |
5076 KB |
Output is correct |
25 |
Correct |
3 ms |
5076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1047 ms |
14784 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
199 ms |
10752 KB |
Output is correct |
2 |
Correct |
210 ms |
10684 KB |
Output is correct |
3 |
Correct |
215 ms |
10712 KB |
Output is correct |
4 |
Correct |
196 ms |
10720 KB |
Output is correct |
5 |
Correct |
194 ms |
10792 KB |
Output is correct |
6 |
Correct |
233 ms |
11460 KB |
Output is correct |
7 |
Correct |
204 ms |
11044 KB |
Output is correct |
8 |
Correct |
196 ms |
10572 KB |
Output is correct |
9 |
Correct |
195 ms |
10604 KB |
Output is correct |
10 |
Correct |
207 ms |
10912 KB |
Output is correct |
11 |
Correct |
3 ms |
5076 KB |
Output is correct |
12 |
Correct |
36 ms |
10132 KB |
Output is correct |
13 |
Correct |
36 ms |
10196 KB |
Output is correct |
14 |
Correct |
35 ms |
10128 KB |
Output is correct |
15 |
Correct |
36 ms |
10168 KB |
Output is correct |
16 |
Correct |
36 ms |
10064 KB |
Output is correct |
17 |
Correct |
41 ms |
10116 KB |
Output is correct |
18 |
Correct |
40 ms |
10196 KB |
Output is correct |
19 |
Correct |
39 ms |
10188 KB |
Output is correct |
20 |
Correct |
3 ms |
5076 KB |
Output is correct |
21 |
Correct |
3 ms |
5076 KB |
Output is correct |
22 |
Correct |
4 ms |
5204 KB |
Output is correct |
23 |
Correct |
35 ms |
10104 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5076 KB |
Output is correct |
2 |
Correct |
3 ms |
5076 KB |
Output is correct |
3 |
Correct |
3 ms |
5076 KB |
Output is correct |
4 |
Correct |
3 ms |
5076 KB |
Output is correct |
5 |
Correct |
3 ms |
5076 KB |
Output is correct |
6 |
Correct |
4 ms |
5076 KB |
Output is correct |
7 |
Correct |
3 ms |
5076 KB |
Output is correct |
8 |
Correct |
3 ms |
5076 KB |
Output is correct |
9 |
Correct |
3 ms |
5076 KB |
Output is correct |
10 |
Correct |
3 ms |
5076 KB |
Output is correct |
11 |
Correct |
2 ms |
5076 KB |
Output is correct |
12 |
Correct |
3 ms |
5204 KB |
Output is correct |
13 |
Correct |
3 ms |
5076 KB |
Output is correct |
14 |
Correct |
3 ms |
5076 KB |
Output is correct |
15 |
Correct |
3 ms |
5076 KB |
Output is correct |
16 |
Correct |
3 ms |
5076 KB |
Output is correct |
17 |
Correct |
3 ms |
5076 KB |
Output is correct |
18 |
Correct |
3 ms |
5076 KB |
Output is correct |
19 |
Correct |
3 ms |
5076 KB |
Output is correct |
20 |
Correct |
3 ms |
5076 KB |
Output is correct |
21 |
Correct |
4 ms |
5076 KB |
Output is correct |
22 |
Correct |
3 ms |
5076 KB |
Output is correct |
23 |
Correct |
3 ms |
5076 KB |
Output is correct |
24 |
Correct |
4 ms |
5076 KB |
Output is correct |
25 |
Correct |
3 ms |
5076 KB |
Output is correct |
26 |
Correct |
4 ms |
5076 KB |
Output is correct |
27 |
Correct |
5 ms |
5204 KB |
Output is correct |
28 |
Correct |
7 ms |
5332 KB |
Output is correct |
29 |
Correct |
4 ms |
5204 KB |
Output is correct |
30 |
Correct |
6 ms |
5204 KB |
Output is correct |
31 |
Correct |
6 ms |
5348 KB |
Output is correct |
32 |
Correct |
4 ms |
5204 KB |
Output is correct |
33 |
Correct |
6 ms |
5240 KB |
Output is correct |
34 |
Correct |
7 ms |
5332 KB |
Output is correct |
35 |
Correct |
4 ms |
5108 KB |
Output is correct |
36 |
Correct |
4 ms |
5076 KB |
Output is correct |
37 |
Correct |
3 ms |
5076 KB |
Output is correct |
38 |
Correct |
3 ms |
5076 KB |
Output is correct |
39 |
Correct |
3 ms |
5076 KB |
Output is correct |
40 |
Correct |
3 ms |
5076 KB |
Output is correct |
41 |
Correct |
3 ms |
5076 KB |
Output is correct |
42 |
Correct |
3 ms |
5028 KB |
Output is correct |
43 |
Correct |
3 ms |
5076 KB |
Output is correct |
44 |
Correct |
3 ms |
5076 KB |
Output is correct |
45 |
Correct |
3 ms |
5076 KB |
Output is correct |
46 |
Correct |
3 ms |
5076 KB |
Output is correct |
47 |
Correct |
3 ms |
5076 KB |
Output is correct |
48 |
Correct |
3 ms |
5076 KB |
Output is correct |
49 |
Correct |
2 ms |
5076 KB |
Output is correct |
50 |
Correct |
3 ms |
5076 KB |
Output is correct |
51 |
Correct |
3 ms |
5076 KB |
Output is correct |
52 |
Correct |
2 ms |
5076 KB |
Output is correct |
53 |
Correct |
3 ms |
5076 KB |
Output is correct |
54 |
Correct |
13 ms |
5580 KB |
Output is correct |
55 |
Correct |
13 ms |
5588 KB |
Output is correct |
56 |
Correct |
8 ms |
5332 KB |
Output is correct |
57 |
Correct |
7 ms |
5272 KB |
Output is correct |
58 |
Correct |
7 ms |
5588 KB |
Output is correct |
59 |
Correct |
6 ms |
5588 KB |
Output is correct |
60 |
Correct |
8 ms |
5324 KB |
Output is correct |
61 |
Correct |
7 ms |
5204 KB |
Output is correct |
62 |
Correct |
6 ms |
5588 KB |
Output is correct |
63 |
Correct |
5 ms |
5592 KB |
Output is correct |
64 |
Correct |
5 ms |
5204 KB |
Output is correct |
65 |
Correct |
8 ms |
5332 KB |
Output is correct |
66 |
Correct |
5 ms |
5588 KB |
Output is correct |
67 |
Correct |
7 ms |
5532 KB |
Output is correct |
68 |
Correct |
8 ms |
5332 KB |
Output is correct |
69 |
Correct |
8 ms |
5280 KB |
Output is correct |
70 |
Correct |
7 ms |
5236 KB |
Output is correct |
71 |
Correct |
7 ms |
5204 KB |
Output is correct |
72 |
Correct |
5 ms |
5476 KB |
Output is correct |
73 |
Correct |
5 ms |
5460 KB |
Output is correct |
74 |
Correct |
6 ms |
5412 KB |
Output is correct |
75 |
Correct |
7 ms |
5332 KB |
Output is correct |
76 |
Correct |
9 ms |
5664 KB |
Output is correct |
77 |
Correct |
6 ms |
5584 KB |
Output is correct |
78 |
Correct |
7 ms |
5204 KB |
Output is correct |
79 |
Correct |
8 ms |
5204 KB |
Output is correct |
80 |
Correct |
4 ms |
5204 KB |
Output is correct |
81 |
Correct |
4 ms |
5204 KB |
Output is correct |
82 |
Correct |
6 ms |
5332 KB |
Output is correct |
83 |
Correct |
6 ms |
5276 KB |
Output is correct |
84 |
Correct |
5 ms |
5332 KB |
Output is correct |
85 |
Correct |
5 ms |
5220 KB |
Output is correct |
86 |
Correct |
6 ms |
5332 KB |
Output is correct |
87 |
Correct |
7 ms |
5408 KB |
Output is correct |
88 |
Correct |
9 ms |
5332 KB |
Output is correct |
89 |
Correct |
8 ms |
5332 KB |
Output is correct |
90 |
Correct |
10 ms |
5280 KB |
Output is correct |
91 |
Correct |
7 ms |
5204 KB |
Output is correct |
92 |
Correct |
4 ms |
5408 KB |
Output is correct |
93 |
Correct |
4 ms |
5460 KB |
Output is correct |
94 |
Correct |
5 ms |
5540 KB |
Output is correct |
95 |
Correct |
6 ms |
5536 KB |
Output is correct |
96 |
Correct |
6 ms |
5460 KB |
Output is correct |
97 |
Correct |
5 ms |
5460 KB |
Output is correct |
98 |
Correct |
5 ms |
5460 KB |
Output is correct |
99 |
Correct |
5 ms |
5460 KB |
Output is correct |
100 |
Correct |
5 ms |
5408 KB |
Output is correct |
101 |
Correct |
6 ms |
5536 KB |
Output is correct |
102 |
Correct |
3 ms |
5016 KB |
Output is correct |
103 |
Correct |
3 ms |
5076 KB |
Output is correct |
104 |
Correct |
3 ms |
5076 KB |
Output is correct |
105 |
Correct |
3 ms |
5016 KB |
Output is correct |
106 |
Correct |
3 ms |
5076 KB |
Output is correct |
107 |
Correct |
3 ms |
5076 KB |
Output is correct |
108 |
Correct |
3 ms |
5076 KB |
Output is correct |
109 |
Correct |
3 ms |
5076 KB |
Output is correct |
110 |
Correct |
3 ms |
5076 KB |
Output is correct |
111 |
Correct |
4 ms |
5016 KB |
Output is correct |
112 |
Correct |
3 ms |
5140 KB |
Output is correct |
113 |
Correct |
4 ms |
5276 KB |
Output is correct |
114 |
Correct |
4 ms |
5332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1047 ms |
14784 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |