#include <time.h>
#include <cstdlib>
#include <stack>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <map>
#include <set>
#include <iterator>
#include <deque>
#include <queue>
#include <sstream>
#include <array>
#include <string>
#include <tuple>
#include <chrono>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <list>
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <bitset>
#include "swap.h"
#include <cassert>
#include <cstdio>
using namespace std;
vector<int> g[200005];
pair<int, int> p[200005];
map<pair<int, int>, int> mp, pos;
set<pair<int, int>> st;
int x, y, mx;
bool ok = 0, ok1;
vector<int> A, B, C;
bool us[200005];
vector<int> ff[200005];
void init(int N, int M,
std::vector<int> U, std::vector<int> V, std::vector<int> W) {
x = N;
y = M;
if(x - 1 != y) ok = 1;
for(int i = 0; i < M; i++){
int a = U[i] + 1, b = V[i] + 1, c = W[i];
if(a != 1) ok = 1;
mp[{a, b}] = c;
mp[{b, a}] = c;
pos[{a, b}] = i + 1;
pos[{b, a}] = i + 1;
ff[a].push_back(b);
ff[b].push_back(a);
st.insert({c, i + 1});
A.push_back(a);
B.push_back(b);
C.push_back(c);
}
for(int i = 1; i <= x; i++){
if(ff[i].size() > 2) ok1 = 1;
}
}
int kol = 0, kol1 = 0;
int dist[200005];
void dfs(int k){
us[k] = 1;
kol++;
kol1 += int(g[k].size());
for(int to : g[k]){
if(us[to]) continue;
dfs(to);
}
}
int getMinimumFuelCapacity(int X, int Y) {
if(!ok1){
if(x == y) return st.rbegin()->first;
else return -1;
}
if(ok){
X++;
Y++;
int L = 0, R = 1e9 + 1;
while(L + 1 < R){
int mid = (L + R) / 2;
kol = 0;
for(int i = 0; i <= x; i++){
g[i].clear();
us[i] = 0;
}
for(int i = 0; i < y; i++){
if(C[i] <= mid){
g[A[i]].push_back(B[i]);
g[B[i]].push_back(A[i]);
}
}
int kk = 0;
kol1 = kol = 0;
dfs(X);
kol1 /= 2;
for(int i = 1; i <= x; i++)
if(us[i] == 1 && g[i].size() >= 3) kk++;
if(!us[Y]){
L = mid;
continue;
}
if(kol - 1 == kol1 && kk == 0){
L = mid;
continue;
}
R = mid;
continue;
}
if(R == 1000000001) return -1;
return R;
}
else{
X++;
Y++;
if(x <= 3)
return -1;
int mx = 0;
if(X != 1) mx = mp[{1, X}];
if(Y != 1) mx = max(mx, mp[{1, Y}]);
if(X != 1) st.erase({mp[{1, X}], pos[{1, X}]});
if(Y != 1) st.erase({mp[{1, Y}], pos[{1, Y}]});
pair<int, int> p = *st.begin();
st.erase(st.begin());
if(X != 1 && Y != 1){
st.insert(p);
if(X != 1) st.insert({mp[{1, X}], pos[{1, X}]});
if(Y != 1) st.insert({mp[{1, Y}], pos[{1, Y}]});
return max(mx, p.first);
}
else{
pair<int, int> p1 = *st.begin();
st.insert(p1);
st.insert(p);
if(X != 1) st.insert({mp[{1, X}], pos[{1, X}]});
if(Y != 1) st.insert({mp[{1, Y}], pos[{1, Y}]});
return max({mx, p.first, p1.first});
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
12208 KB |
Output is correct |
2 |
Correct |
5 ms |
9820 KB |
Output is correct |
3 |
Correct |
3 ms |
12124 KB |
Output is correct |
4 |
Correct |
4 ms |
12376 KB |
Output is correct |
5 |
Correct |
4 ms |
12380 KB |
Output is correct |
6 |
Correct |
4 ms |
12376 KB |
Output is correct |
7 |
Correct |
4 ms |
12380 KB |
Output is correct |
8 |
Correct |
4 ms |
12380 KB |
Output is correct |
9 |
Correct |
244 ms |
41772 KB |
Output is correct |
10 |
Correct |
432 ms |
48332 KB |
Output is correct |
11 |
Correct |
399 ms |
47812 KB |
Output is correct |
12 |
Correct |
316 ms |
49720 KB |
Output is correct |
13 |
Correct |
385 ms |
47520 KB |
Output is correct |
14 |
Correct |
320 ms |
39520 KB |
Output is correct |
15 |
Correct |
426 ms |
50100 KB |
Output is correct |
16 |
Correct |
401 ms |
50436 KB |
Output is correct |
17 |
Correct |
504 ms |
52776 KB |
Output is correct |
18 |
Correct |
437 ms |
52736 KB |
Output is correct |
19 |
Correct |
67 ms |
22612 KB |
Output is correct |
20 |
Correct |
435 ms |
52668 KB |
Output is correct |
21 |
Correct |
428 ms |
51552 KB |
Output is correct |
22 |
Correct |
445 ms |
54256 KB |
Output is correct |
23 |
Correct |
493 ms |
54200 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
12208 KB |
Output is correct |
2 |
Correct |
5 ms |
9820 KB |
Output is correct |
3 |
Correct |
1304 ms |
52008 KB |
Output is correct |
4 |
Correct |
1252 ms |
51692 KB |
Output is correct |
5 |
Correct |
1306 ms |
52892 KB |
Output is correct |
6 |
Correct |
1286 ms |
52720 KB |
Output is correct |
7 |
Correct |
1215 ms |
53432 KB |
Output is correct |
8 |
Correct |
1258 ms |
50248 KB |
Output is correct |
9 |
Correct |
1165 ms |
50848 KB |
Output is correct |
10 |
Correct |
1126 ms |
49240 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
12208 KB |
Output is correct |
2 |
Correct |
5 ms |
9820 KB |
Output is correct |
3 |
Correct |
3 ms |
12124 KB |
Output is correct |
4 |
Correct |
4 ms |
12376 KB |
Output is correct |
5 |
Correct |
4 ms |
12380 KB |
Output is correct |
6 |
Correct |
4 ms |
12376 KB |
Output is correct |
7 |
Correct |
4 ms |
12380 KB |
Output is correct |
8 |
Correct |
4 ms |
12380 KB |
Output is correct |
9 |
Correct |
4 ms |
9820 KB |
Output is correct |
10 |
Correct |
7 ms |
10076 KB |
Output is correct |
11 |
Correct |
8 ms |
10112 KB |
Output is correct |
12 |
Correct |
8 ms |
10072 KB |
Output is correct |
13 |
Correct |
7 ms |
10076 KB |
Output is correct |
14 |
Correct |
9 ms |
11096 KB |
Output is correct |
15 |
Correct |
10 ms |
11084 KB |
Output is correct |
16 |
Correct |
8 ms |
12632 KB |
Output is correct |
17 |
Correct |
6 ms |
12636 KB |
Output is correct |
18 |
Correct |
6 ms |
12516 KB |
Output is correct |
19 |
Correct |
8 ms |
10076 KB |
Output is correct |
20 |
Correct |
8 ms |
10076 KB |
Output is correct |
21 |
Correct |
7 ms |
10284 KB |
Output is correct |
22 |
Correct |
7 ms |
10332 KB |
Output is correct |
23 |
Correct |
9 ms |
10076 KB |
Output is correct |
24 |
Correct |
8 ms |
10408 KB |
Output is correct |
25 |
Correct |
10 ms |
10412 KB |
Output is correct |
26 |
Correct |
10 ms |
10552 KB |
Output is correct |
27 |
Correct |
10 ms |
10280 KB |
Output is correct |
28 |
Correct |
8 ms |
10588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
9820 KB |
Output is correct |
2 |
Correct |
4 ms |
12208 KB |
Output is correct |
3 |
Correct |
5 ms |
9820 KB |
Output is correct |
4 |
Correct |
3 ms |
12124 KB |
Output is correct |
5 |
Correct |
4 ms |
12376 KB |
Output is correct |
6 |
Correct |
4 ms |
12380 KB |
Output is correct |
7 |
Correct |
4 ms |
12376 KB |
Output is correct |
8 |
Correct |
4 ms |
12380 KB |
Output is correct |
9 |
Correct |
4 ms |
12380 KB |
Output is correct |
10 |
Correct |
244 ms |
41772 KB |
Output is correct |
11 |
Correct |
432 ms |
48332 KB |
Output is correct |
12 |
Correct |
399 ms |
47812 KB |
Output is correct |
13 |
Correct |
316 ms |
49720 KB |
Output is correct |
14 |
Correct |
385 ms |
47520 KB |
Output is correct |
15 |
Correct |
7 ms |
10076 KB |
Output is correct |
16 |
Correct |
8 ms |
10112 KB |
Output is correct |
17 |
Correct |
8 ms |
10072 KB |
Output is correct |
18 |
Correct |
7 ms |
10076 KB |
Output is correct |
19 |
Correct |
9 ms |
11096 KB |
Output is correct |
20 |
Correct |
10 ms |
11084 KB |
Output is correct |
21 |
Correct |
8 ms |
12632 KB |
Output is correct |
22 |
Correct |
6 ms |
12636 KB |
Output is correct |
23 |
Correct |
6 ms |
12516 KB |
Output is correct |
24 |
Correct |
8 ms |
10076 KB |
Output is correct |
25 |
Correct |
8 ms |
10076 KB |
Output is correct |
26 |
Correct |
7 ms |
10284 KB |
Output is correct |
27 |
Correct |
7 ms |
10332 KB |
Output is correct |
28 |
Correct |
9 ms |
10076 KB |
Output is correct |
29 |
Correct |
8 ms |
10408 KB |
Output is correct |
30 |
Correct |
10 ms |
10412 KB |
Output is correct |
31 |
Correct |
10 ms |
10552 KB |
Output is correct |
32 |
Correct |
10 ms |
10280 KB |
Output is correct |
33 |
Correct |
8 ms |
10588 KB |
Output is correct |
34 |
Correct |
37 ms |
15360 KB |
Output is correct |
35 |
Correct |
984 ms |
51920 KB |
Output is correct |
36 |
Correct |
949 ms |
50884 KB |
Output is correct |
37 |
Correct |
1014 ms |
49980 KB |
Output is correct |
38 |
Correct |
1052 ms |
49344 KB |
Output is correct |
39 |
Correct |
935 ms |
50876 KB |
Output is correct |
40 |
Correct |
887 ms |
47764 KB |
Output is correct |
41 |
Correct |
937 ms |
51196 KB |
Output is correct |
42 |
Correct |
1070 ms |
52476 KB |
Output is correct |
43 |
Correct |
987 ms |
54640 KB |
Output is correct |
44 |
Correct |
801 ms |
52276 KB |
Output is correct |
45 |
Correct |
1260 ms |
67808 KB |
Output is correct |
46 |
Correct |
1118 ms |
54180 KB |
Output is correct |
47 |
Correct |
998 ms |
52068 KB |
Output is correct |
48 |
Correct |
1053 ms |
55852 KB |
Output is correct |
49 |
Correct |
744 ms |
68404 KB |
Output is correct |
50 |
Correct |
589 ms |
55508 KB |
Output is correct |
51 |
Correct |
847 ms |
60580 KB |
Output is correct |
52 |
Correct |
1328 ms |
74436 KB |
Output is correct |
53 |
Correct |
1398 ms |
79136 KB |
Output is correct |
54 |
Execution timed out |
2074 ms |
87880 KB |
Time limit exceeded |
55 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
12208 KB |
Output is correct |
2 |
Correct |
5 ms |
9820 KB |
Output is correct |
3 |
Correct |
3 ms |
12124 KB |
Output is correct |
4 |
Correct |
4 ms |
12376 KB |
Output is correct |
5 |
Correct |
4 ms |
12380 KB |
Output is correct |
6 |
Correct |
4 ms |
12376 KB |
Output is correct |
7 |
Correct |
4 ms |
12380 KB |
Output is correct |
8 |
Correct |
4 ms |
12380 KB |
Output is correct |
9 |
Correct |
244 ms |
41772 KB |
Output is correct |
10 |
Correct |
432 ms |
48332 KB |
Output is correct |
11 |
Correct |
399 ms |
47812 KB |
Output is correct |
12 |
Correct |
316 ms |
49720 KB |
Output is correct |
13 |
Correct |
385 ms |
47520 KB |
Output is correct |
14 |
Correct |
320 ms |
39520 KB |
Output is correct |
15 |
Correct |
426 ms |
50100 KB |
Output is correct |
16 |
Correct |
401 ms |
50436 KB |
Output is correct |
17 |
Correct |
504 ms |
52776 KB |
Output is correct |
18 |
Correct |
437 ms |
52736 KB |
Output is correct |
19 |
Correct |
1304 ms |
52008 KB |
Output is correct |
20 |
Correct |
1252 ms |
51692 KB |
Output is correct |
21 |
Correct |
1306 ms |
52892 KB |
Output is correct |
22 |
Correct |
1286 ms |
52720 KB |
Output is correct |
23 |
Correct |
1215 ms |
53432 KB |
Output is correct |
24 |
Correct |
1258 ms |
50248 KB |
Output is correct |
25 |
Correct |
1165 ms |
50848 KB |
Output is correct |
26 |
Correct |
1126 ms |
49240 KB |
Output is correct |
27 |
Correct |
7 ms |
10076 KB |
Output is correct |
28 |
Correct |
8 ms |
10112 KB |
Output is correct |
29 |
Correct |
8 ms |
10072 KB |
Output is correct |
30 |
Correct |
7 ms |
10076 KB |
Output is correct |
31 |
Correct |
9 ms |
11096 KB |
Output is correct |
32 |
Correct |
10 ms |
11084 KB |
Output is correct |
33 |
Correct |
8 ms |
12632 KB |
Output is correct |
34 |
Correct |
6 ms |
12636 KB |
Output is correct |
35 |
Correct |
6 ms |
12516 KB |
Output is correct |
36 |
Correct |
37 ms |
15360 KB |
Output is correct |
37 |
Correct |
984 ms |
51920 KB |
Output is correct |
38 |
Correct |
949 ms |
50884 KB |
Output is correct |
39 |
Correct |
1014 ms |
49980 KB |
Output is correct |
40 |
Correct |
1052 ms |
49344 KB |
Output is correct |
41 |
Correct |
935 ms |
50876 KB |
Output is correct |
42 |
Correct |
887 ms |
47764 KB |
Output is correct |
43 |
Correct |
937 ms |
51196 KB |
Output is correct |
44 |
Correct |
1070 ms |
52476 KB |
Output is correct |
45 |
Correct |
987 ms |
54640 KB |
Output is correct |
46 |
Correct |
801 ms |
52276 KB |
Output is correct |
47 |
Execution timed out |
2017 ms |
17500 KB |
Time limit exceeded |
48 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
9820 KB |
Output is correct |
2 |
Correct |
4 ms |
12208 KB |
Output is correct |
3 |
Correct |
5 ms |
9820 KB |
Output is correct |
4 |
Correct |
3 ms |
12124 KB |
Output is correct |
5 |
Correct |
4 ms |
12376 KB |
Output is correct |
6 |
Correct |
4 ms |
12380 KB |
Output is correct |
7 |
Correct |
4 ms |
12376 KB |
Output is correct |
8 |
Correct |
4 ms |
12380 KB |
Output is correct |
9 |
Correct |
4 ms |
12380 KB |
Output is correct |
10 |
Correct |
244 ms |
41772 KB |
Output is correct |
11 |
Correct |
432 ms |
48332 KB |
Output is correct |
12 |
Correct |
399 ms |
47812 KB |
Output is correct |
13 |
Correct |
316 ms |
49720 KB |
Output is correct |
14 |
Correct |
385 ms |
47520 KB |
Output is correct |
15 |
Correct |
320 ms |
39520 KB |
Output is correct |
16 |
Correct |
426 ms |
50100 KB |
Output is correct |
17 |
Correct |
401 ms |
50436 KB |
Output is correct |
18 |
Correct |
504 ms |
52776 KB |
Output is correct |
19 |
Correct |
437 ms |
52736 KB |
Output is correct |
20 |
Correct |
1304 ms |
52008 KB |
Output is correct |
21 |
Correct |
1252 ms |
51692 KB |
Output is correct |
22 |
Correct |
1306 ms |
52892 KB |
Output is correct |
23 |
Correct |
1286 ms |
52720 KB |
Output is correct |
24 |
Correct |
1215 ms |
53432 KB |
Output is correct |
25 |
Correct |
1258 ms |
50248 KB |
Output is correct |
26 |
Correct |
1165 ms |
50848 KB |
Output is correct |
27 |
Correct |
1126 ms |
49240 KB |
Output is correct |
28 |
Correct |
7 ms |
10076 KB |
Output is correct |
29 |
Correct |
8 ms |
10112 KB |
Output is correct |
30 |
Correct |
8 ms |
10072 KB |
Output is correct |
31 |
Correct |
7 ms |
10076 KB |
Output is correct |
32 |
Correct |
9 ms |
11096 KB |
Output is correct |
33 |
Correct |
10 ms |
11084 KB |
Output is correct |
34 |
Correct |
8 ms |
12632 KB |
Output is correct |
35 |
Correct |
6 ms |
12636 KB |
Output is correct |
36 |
Correct |
6 ms |
12516 KB |
Output is correct |
37 |
Correct |
37 ms |
15360 KB |
Output is correct |
38 |
Correct |
984 ms |
51920 KB |
Output is correct |
39 |
Correct |
949 ms |
50884 KB |
Output is correct |
40 |
Correct |
1014 ms |
49980 KB |
Output is correct |
41 |
Correct |
1052 ms |
49344 KB |
Output is correct |
42 |
Correct |
935 ms |
50876 KB |
Output is correct |
43 |
Correct |
887 ms |
47764 KB |
Output is correct |
44 |
Correct |
937 ms |
51196 KB |
Output is correct |
45 |
Correct |
1070 ms |
52476 KB |
Output is correct |
46 |
Correct |
987 ms |
54640 KB |
Output is correct |
47 |
Correct |
801 ms |
52276 KB |
Output is correct |
48 |
Execution timed out |
2017 ms |
17500 KB |
Time limit exceeded |
49 |
Halted |
0 ms |
0 KB |
- |