#include "swap.h"
#include<bits/stdc++.h>
#include <vector>
#define pb push_back
#define F first
#define S second
using namespace std;
const int N = 1e6 + 5;
vector<pair<int, int> > g[N];
vector<pair<int, pair<int, int> > > edges;
int mx, n, m, component[N], deg[N], max_deg[N], edg_cnt[N], cnt[N];
bool sb2 = 1, sb1 = 1;
int find(int x){
while(true){
if(x == component[x])
return x;
component[x] = component[component[x]];
x = component[x];
}
}
void merge(int a, int b){
int u = find(a), v = find(b);
deg[a]++;
deg[b]++;
max_deg[v] = max({max_deg[v], max_deg[u], deg[a], deg[b]});
if(v != u)
edg_cnt[v] += edg_cnt[u] + 1;
else
edg_cnt[v]++;
if(u != v)
cnt[v] += cnt[u];
component[u] = v;
}
void init(int N, int M,
std::vector<int> U, std::vector<int> V, std::vector<int> W) {
n = N;
m = M;
int wut = 0;
map<int, int> mp;
for(int i = 0; i < M; ++i){
int u = U[i], v = V[i], w = W[i];
if(u != 0 and v != 0)
sb2 = false;
g[u].pb({w, v});
g[v].pb({w, u});
mx = max(mx, w);
edges.pb({w, {u ,v}});
mp[u]++;
mp[v]++;
}
for(int i = 0; i < n; ++i)
sort(g[i].begin(), g[i].end());
sort(edges.begin(), edges.end());
for(auto k : mp)
wut = max(wut, k.S);
if(wut > 2)
sb1 = false;
}
int getMinimumFuelCapacity(int X, int Y) {
if(sb2 and m == n - 1){
if(n <= 3) return -1;
if(X == 0){
int x = g[Y][0].F, xx, dest, mn;
if(g[0][0].S != Y){
xx = g[0][0].F;
dest = g[0][0].S;
}else{
xx = g[0][1].F;
dest = g[0][1].S;
}
if(g[0][1].S != Y and g[0][1].S != dest)
mn = g[0][1].F;
else
mn = g[0][2].F;
return max({x, xx, mn});
}
int x = g[X][0].F, xx = g[Y][0].F, mn;
if(g[0][0].S != X and g[0][0].S != Y)
mn = g[0][0].F;
else if(g[0][1].S != X and g[0][1].S != Y)
mn = g[0][1].F;
else
mn = g[0][2].F;
return max({x, xx, mn});
}
if(sb1){
if(m == n - 1)
return -1;
else
return mx;
}
for(int i = 0; i < n; ++i){
component[i] = i;
deg[i] = 0;
max_deg[i] = 0;
edg_cnt[i] = 0;
cnt[i] = 1;
}
for(auto k : edges){
int u = k.S.F, v = k.S.S, c = k.F;
merge(u, v);
// cout << ((max_deg[find(X)] > 2) or (edg_cnt[find(X)] >= cnt[find(X)])) << endl;
if(find(X) == find(Y) and ((max_deg[find(X)] > 2) or (edg_cnt[find(X)] >= cnt[find(X)])))
return c;
}
return -1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
23764 KB |
Output is correct |
2 |
Correct |
13 ms |
23776 KB |
Output is correct |
3 |
Correct |
12 ms |
23780 KB |
Output is correct |
4 |
Correct |
12 ms |
23764 KB |
Output is correct |
5 |
Correct |
12 ms |
23892 KB |
Output is correct |
6 |
Correct |
13 ms |
23864 KB |
Output is correct |
7 |
Correct |
14 ms |
23864 KB |
Output is correct |
8 |
Correct |
13 ms |
23784 KB |
Output is correct |
9 |
Correct |
118 ms |
33084 KB |
Output is correct |
10 |
Correct |
144 ms |
34648 KB |
Output is correct |
11 |
Correct |
143 ms |
34412 KB |
Output is correct |
12 |
Correct |
189 ms |
35032 KB |
Output is correct |
13 |
Correct |
175 ms |
35192 KB |
Output is correct |
14 |
Correct |
117 ms |
33156 KB |
Output is correct |
15 |
Correct |
218 ms |
36516 KB |
Output is correct |
16 |
Correct |
196 ms |
36272 KB |
Output is correct |
17 |
Correct |
210 ms |
36896 KB |
Output is correct |
18 |
Correct |
243 ms |
36876 KB |
Output is correct |
19 |
Correct |
72 ms |
29060 KB |
Output is correct |
20 |
Correct |
197 ms |
37632 KB |
Output is correct |
21 |
Correct |
193 ms |
37512 KB |
Output is correct |
22 |
Correct |
238 ms |
38292 KB |
Output is correct |
23 |
Correct |
217 ms |
38336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
23764 KB |
Output is correct |
2 |
Correct |
13 ms |
23776 KB |
Output is correct |
3 |
Correct |
196 ms |
38268 KB |
Output is correct |
4 |
Correct |
187 ms |
38676 KB |
Output is correct |
5 |
Correct |
178 ms |
38736 KB |
Output is correct |
6 |
Correct |
185 ms |
38552 KB |
Output is correct |
7 |
Correct |
228 ms |
38652 KB |
Output is correct |
8 |
Correct |
170 ms |
38168 KB |
Output is correct |
9 |
Correct |
178 ms |
38588 KB |
Output is correct |
10 |
Correct |
189 ms |
38288 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
23764 KB |
Output is correct |
2 |
Correct |
13 ms |
23776 KB |
Output is correct |
3 |
Correct |
12 ms |
23780 KB |
Output is correct |
4 |
Correct |
12 ms |
23764 KB |
Output is correct |
5 |
Correct |
12 ms |
23892 KB |
Output is correct |
6 |
Correct |
13 ms |
23864 KB |
Output is correct |
7 |
Correct |
14 ms |
23864 KB |
Output is correct |
8 |
Correct |
13 ms |
23784 KB |
Output is correct |
9 |
Correct |
12 ms |
23764 KB |
Output is correct |
10 |
Correct |
14 ms |
23892 KB |
Output is correct |
11 |
Correct |
13 ms |
23892 KB |
Output is correct |
12 |
Correct |
12 ms |
23892 KB |
Output is correct |
13 |
Correct |
13 ms |
23828 KB |
Output is correct |
14 |
Correct |
13 ms |
23896 KB |
Output is correct |
15 |
Correct |
12 ms |
23908 KB |
Output is correct |
16 |
Correct |
13 ms |
23932 KB |
Output is correct |
17 |
Correct |
14 ms |
23904 KB |
Output is correct |
18 |
Correct |
14 ms |
23924 KB |
Output is correct |
19 |
Correct |
13 ms |
23900 KB |
Output is correct |
20 |
Correct |
13 ms |
23892 KB |
Output is correct |
21 |
Correct |
14 ms |
23892 KB |
Output is correct |
22 |
Correct |
13 ms |
23892 KB |
Output is correct |
23 |
Correct |
14 ms |
23892 KB |
Output is correct |
24 |
Correct |
13 ms |
23892 KB |
Output is correct |
25 |
Correct |
14 ms |
24020 KB |
Output is correct |
26 |
Correct |
13 ms |
24020 KB |
Output is correct |
27 |
Correct |
14 ms |
23892 KB |
Output is correct |
28 |
Correct |
16 ms |
23968 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
11 ms |
23764 KB |
Output is correct |
3 |
Correct |
13 ms |
23776 KB |
Output is correct |
4 |
Correct |
12 ms |
23780 KB |
Output is correct |
5 |
Correct |
12 ms |
23764 KB |
Output is correct |
6 |
Correct |
12 ms |
23892 KB |
Output is correct |
7 |
Correct |
13 ms |
23864 KB |
Output is correct |
8 |
Correct |
14 ms |
23864 KB |
Output is correct |
9 |
Correct |
13 ms |
23784 KB |
Output is correct |
10 |
Correct |
118 ms |
33084 KB |
Output is correct |
11 |
Correct |
144 ms |
34648 KB |
Output is correct |
12 |
Correct |
143 ms |
34412 KB |
Output is correct |
13 |
Correct |
189 ms |
35032 KB |
Output is correct |
14 |
Correct |
175 ms |
35192 KB |
Output is correct |
15 |
Correct |
14 ms |
23892 KB |
Output is correct |
16 |
Correct |
13 ms |
23892 KB |
Output is correct |
17 |
Correct |
12 ms |
23892 KB |
Output is correct |
18 |
Correct |
13 ms |
23828 KB |
Output is correct |
19 |
Correct |
13 ms |
23896 KB |
Output is correct |
20 |
Correct |
12 ms |
23908 KB |
Output is correct |
21 |
Correct |
13 ms |
23932 KB |
Output is correct |
22 |
Correct |
14 ms |
23904 KB |
Output is correct |
23 |
Correct |
14 ms |
23924 KB |
Output is correct |
24 |
Correct |
13 ms |
23900 KB |
Output is correct |
25 |
Correct |
13 ms |
23892 KB |
Output is correct |
26 |
Correct |
14 ms |
23892 KB |
Output is correct |
27 |
Correct |
13 ms |
23892 KB |
Output is correct |
28 |
Correct |
14 ms |
23892 KB |
Output is correct |
29 |
Correct |
13 ms |
23892 KB |
Output is correct |
30 |
Correct |
14 ms |
24020 KB |
Output is correct |
31 |
Correct |
13 ms |
24020 KB |
Output is correct |
32 |
Correct |
14 ms |
23892 KB |
Output is correct |
33 |
Correct |
16 ms |
23968 KB |
Output is correct |
34 |
Correct |
27 ms |
25628 KB |
Output is correct |
35 |
Correct |
186 ms |
35884 KB |
Output is correct |
36 |
Correct |
170 ms |
35888 KB |
Output is correct |
37 |
Correct |
171 ms |
35868 KB |
Output is correct |
38 |
Correct |
180 ms |
35952 KB |
Output is correct |
39 |
Correct |
169 ms |
35740 KB |
Output is correct |
40 |
Correct |
162 ms |
34916 KB |
Output is correct |
41 |
Correct |
188 ms |
35952 KB |
Output is correct |
42 |
Correct |
180 ms |
35956 KB |
Output is correct |
43 |
Correct |
164 ms |
35964 KB |
Output is correct |
44 |
Correct |
182 ms |
36384 KB |
Output is correct |
45 |
Correct |
247 ms |
38448 KB |
Output is correct |
46 |
Correct |
182 ms |
35936 KB |
Output is correct |
47 |
Correct |
178 ms |
35828 KB |
Output is correct |
48 |
Correct |
201 ms |
36344 KB |
Output is correct |
49 |
Correct |
111 ms |
34264 KB |
Output is correct |
50 |
Correct |
101 ms |
32032 KB |
Output is correct |
51 |
Correct |
178 ms |
35500 KB |
Output is correct |
52 |
Correct |
265 ms |
39816 KB |
Output is correct |
53 |
Correct |
300 ms |
40644 KB |
Output is correct |
54 |
Correct |
327 ms |
42240 KB |
Output is correct |
55 |
Correct |
170 ms |
36048 KB |
Output is correct |
56 |
Correct |
287 ms |
40316 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
23764 KB |
Output is correct |
2 |
Correct |
13 ms |
23776 KB |
Output is correct |
3 |
Correct |
12 ms |
23780 KB |
Output is correct |
4 |
Correct |
12 ms |
23764 KB |
Output is correct |
5 |
Correct |
12 ms |
23892 KB |
Output is correct |
6 |
Correct |
13 ms |
23864 KB |
Output is correct |
7 |
Correct |
14 ms |
23864 KB |
Output is correct |
8 |
Correct |
13 ms |
23784 KB |
Output is correct |
9 |
Correct |
118 ms |
33084 KB |
Output is correct |
10 |
Correct |
144 ms |
34648 KB |
Output is correct |
11 |
Correct |
143 ms |
34412 KB |
Output is correct |
12 |
Correct |
189 ms |
35032 KB |
Output is correct |
13 |
Correct |
175 ms |
35192 KB |
Output is correct |
14 |
Correct |
117 ms |
33156 KB |
Output is correct |
15 |
Correct |
218 ms |
36516 KB |
Output is correct |
16 |
Correct |
196 ms |
36272 KB |
Output is correct |
17 |
Correct |
210 ms |
36896 KB |
Output is correct |
18 |
Correct |
243 ms |
36876 KB |
Output is correct |
19 |
Correct |
196 ms |
38268 KB |
Output is correct |
20 |
Correct |
187 ms |
38676 KB |
Output is correct |
21 |
Correct |
178 ms |
38736 KB |
Output is correct |
22 |
Correct |
185 ms |
38552 KB |
Output is correct |
23 |
Correct |
228 ms |
38652 KB |
Output is correct |
24 |
Correct |
170 ms |
38168 KB |
Output is correct |
25 |
Correct |
178 ms |
38588 KB |
Output is correct |
26 |
Correct |
189 ms |
38288 KB |
Output is correct |
27 |
Correct |
14 ms |
23892 KB |
Output is correct |
28 |
Correct |
13 ms |
23892 KB |
Output is correct |
29 |
Correct |
12 ms |
23892 KB |
Output is correct |
30 |
Correct |
13 ms |
23828 KB |
Output is correct |
31 |
Correct |
13 ms |
23896 KB |
Output is correct |
32 |
Correct |
12 ms |
23908 KB |
Output is correct |
33 |
Correct |
13 ms |
23932 KB |
Output is correct |
34 |
Correct |
14 ms |
23904 KB |
Output is correct |
35 |
Correct |
14 ms |
23924 KB |
Output is correct |
36 |
Correct |
27 ms |
25628 KB |
Output is correct |
37 |
Correct |
186 ms |
35884 KB |
Output is correct |
38 |
Correct |
170 ms |
35888 KB |
Output is correct |
39 |
Correct |
171 ms |
35868 KB |
Output is correct |
40 |
Correct |
180 ms |
35952 KB |
Output is correct |
41 |
Correct |
169 ms |
35740 KB |
Output is correct |
42 |
Correct |
162 ms |
34916 KB |
Output is correct |
43 |
Correct |
188 ms |
35952 KB |
Output is correct |
44 |
Correct |
180 ms |
35956 KB |
Output is correct |
45 |
Correct |
164 ms |
35964 KB |
Output is correct |
46 |
Correct |
182 ms |
36384 KB |
Output is correct |
47 |
Execution timed out |
2075 ms |
25684 KB |
Time limit exceeded |
48 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
11 ms |
23764 KB |
Output is correct |
3 |
Correct |
13 ms |
23776 KB |
Output is correct |
4 |
Correct |
12 ms |
23780 KB |
Output is correct |
5 |
Correct |
12 ms |
23764 KB |
Output is correct |
6 |
Correct |
12 ms |
23892 KB |
Output is correct |
7 |
Correct |
13 ms |
23864 KB |
Output is correct |
8 |
Correct |
14 ms |
23864 KB |
Output is correct |
9 |
Correct |
13 ms |
23784 KB |
Output is correct |
10 |
Correct |
118 ms |
33084 KB |
Output is correct |
11 |
Correct |
144 ms |
34648 KB |
Output is correct |
12 |
Correct |
143 ms |
34412 KB |
Output is correct |
13 |
Correct |
189 ms |
35032 KB |
Output is correct |
14 |
Correct |
175 ms |
35192 KB |
Output is correct |
15 |
Correct |
117 ms |
33156 KB |
Output is correct |
16 |
Correct |
218 ms |
36516 KB |
Output is correct |
17 |
Correct |
196 ms |
36272 KB |
Output is correct |
18 |
Correct |
210 ms |
36896 KB |
Output is correct |
19 |
Correct |
243 ms |
36876 KB |
Output is correct |
20 |
Correct |
196 ms |
38268 KB |
Output is correct |
21 |
Correct |
187 ms |
38676 KB |
Output is correct |
22 |
Correct |
178 ms |
38736 KB |
Output is correct |
23 |
Correct |
185 ms |
38552 KB |
Output is correct |
24 |
Correct |
228 ms |
38652 KB |
Output is correct |
25 |
Correct |
170 ms |
38168 KB |
Output is correct |
26 |
Correct |
178 ms |
38588 KB |
Output is correct |
27 |
Correct |
189 ms |
38288 KB |
Output is correct |
28 |
Correct |
14 ms |
23892 KB |
Output is correct |
29 |
Correct |
13 ms |
23892 KB |
Output is correct |
30 |
Correct |
12 ms |
23892 KB |
Output is correct |
31 |
Correct |
13 ms |
23828 KB |
Output is correct |
32 |
Correct |
13 ms |
23896 KB |
Output is correct |
33 |
Correct |
12 ms |
23908 KB |
Output is correct |
34 |
Correct |
13 ms |
23932 KB |
Output is correct |
35 |
Correct |
14 ms |
23904 KB |
Output is correct |
36 |
Correct |
14 ms |
23924 KB |
Output is correct |
37 |
Correct |
27 ms |
25628 KB |
Output is correct |
38 |
Correct |
186 ms |
35884 KB |
Output is correct |
39 |
Correct |
170 ms |
35888 KB |
Output is correct |
40 |
Correct |
171 ms |
35868 KB |
Output is correct |
41 |
Correct |
180 ms |
35952 KB |
Output is correct |
42 |
Correct |
169 ms |
35740 KB |
Output is correct |
43 |
Correct |
162 ms |
34916 KB |
Output is correct |
44 |
Correct |
188 ms |
35952 KB |
Output is correct |
45 |
Correct |
180 ms |
35956 KB |
Output is correct |
46 |
Correct |
164 ms |
35964 KB |
Output is correct |
47 |
Correct |
182 ms |
36384 KB |
Output is correct |
48 |
Execution timed out |
2075 ms |
25684 KB |
Time limit exceeded |
49 |
Halted |
0 ms |
0 KB |
- |