#include "swap.h"
#include "bits/stdc++.h"
//#include "grader.cpp"
using namespace std;
#define pb push_back
#define ff first
#define ss second
#define sz(x) (int)x.size()
#define int long long
template<class T> bool umin(T& a, const T b) { if(a > b) { a = b; return 1; } return 0; }
template<class T> bool umax(T& a, const T b) { if(a < b) { a = b; return 1; } return 0; }
const int NN = 1e5+5;
int mx = 0, ok, res, d[NN], n, m;
vector<pair<int, int>> edges[NN];
vector<pair<int, int>> mm;
vector<int> tte[NN];
void init(int32_t N, int32_t M,
vector<int32_t> a, vector<int32_t> b, vector<int32_t> c) {
n = N, m = M;
for(int i=0;i<m;i++){
edges[a[i]].pb({b[i], c[i]});
edges[b[i]].pb({a[i], c[i]});
tte[a[i]].pb(c[i]);
tte[b[i]].pb(c[i]);
mx = max(mx, (int)c[i]);
} for(int i=0;i<n;i++) sort(tte[i].begin(), tte[i].end());
}
/*
5 6
0 1 4
0 2 4
1 2 1
1 3 2
2 3 3
1 4 10
3
1 2
2 4
0 1
*/
const int mod = 1e9+7;
int mn[NN], par[NN], bad[NN];
int mn2[NN];
int32_t getMinimumFuelCapacity(int32_t x, int32_t y) {
priority_queue<pair<int, int>> qq;
qq.push({0, x});
memset(mn, 127, sizeof mn);
memset(mn2, 127, sizeof mn2);
memset(bad, 0, sizeof bad);
memset(par, 0, sizeof par);
par[x] = -1;
mn[x] = 0;
while(!qq.empty()){
auto u = qq.top(); qq.pop();
if(mn[u.ss] < -u.ff) continue;
for(auto x : edges[u.ss]) if(umin(mn[x.ff], max(mn[u.ss], x.ss))) par[x.ff] = u.ss, qq.push({-mn[x.ff], x.ff});
}
for(int i=0;i<n;i++) if(sz(tte[i]) >= 3) mn2[i] = tte[i][2], qq.push({-tte[i][2], i});
while(!qq.empty()){
auto u = qq.top(); qq.pop();
if(mn2[u.ss] < -u.ff) continue;
for(auto x : edges[u.ss]) if(umin(mn2[x.ff], max(mn2[u.ss], x.ss))) qq.push({-mn2[x.ff], x.ff});
} int trr = mn[y], tt = y;
vector<int> bads;
while(~tt){
bads.pb(tt);
bad[tt] = 1;
tt = par[tt];
} int rr = mod;
for(int i=0;i<n;i++){
if(bad[i]){
if(i == y || i == x) umin(rr, mn2[i]);
else {
int mn = mod;
for(auto x : edges[i]){
if(bad[x.ff]) continue;
umin(mn, x.ss);
} umin(rr, mn);
}
}
}
int a = x, b = bads[sz(bads)-2];
qq.push({0, x});
for(int i=0;i<n;i++) mn[i] = mod;
mn[x] = 0;
while(!qq.empty()){
auto u = qq.top(); qq.pop();
if(mn[u.ss] < -u.ff) continue;
for(auto x : edges[u.ss]){
if((x.ff == a && u.ss == b) || (x.ff == b && u.ss == a)) continue;
if(umin(mn[x.ff], max(mn[u.ss], x.ss))) qq.push({-mn[x.ff], x.ff});
}
} umin(rr, mn[y]);
a = y, b = bads[1];
qq.push({0, x});
for(int i=0;i<n;i++) mn[i] = mod;
mn[x] = 0;
while(!qq.empty()){
auto u = qq.top(); qq.pop();
if(mn[u.ss] < -u.ff) continue;
for(auto x : edges[u.ss]){
if((x.ff == a && u.ss == b) || (x.ff == b && u.ss == a)) continue;
if(umin(mn[x.ff], max(mn[u.ss], x.ss))) qq.push({-mn[x.ff], x.ff});
}
} umin(rr, mn[y]);
if(rr == mod) return -1;
return max(rr, trr);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
8012 KB |
Output is correct |
2 |
Correct |
5 ms |
8012 KB |
Output is correct |
3 |
Correct |
6 ms |
8012 KB |
Output is correct |
4 |
Correct |
6 ms |
8140 KB |
Output is correct |
5 |
Correct |
7 ms |
8140 KB |
Output is correct |
6 |
Correct |
7 ms |
8236 KB |
Output is correct |
7 |
Correct |
7 ms |
8248 KB |
Output is correct |
8 |
Correct |
7 ms |
8144 KB |
Output is correct |
9 |
Correct |
163 ms |
16532 KB |
Output is correct |
10 |
Correct |
240 ms |
18084 KB |
Output is correct |
11 |
Correct |
286 ms |
18860 KB |
Output is correct |
12 |
Correct |
429 ms |
19348 KB |
Output is correct |
13 |
Correct |
326 ms |
19292 KB |
Output is correct |
14 |
Execution timed out |
2077 ms |
17436 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
8012 KB |
Output is correct |
2 |
Correct |
5 ms |
8012 KB |
Output is correct |
3 |
Execution timed out |
2078 ms |
23276 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
8012 KB |
Output is correct |
2 |
Correct |
5 ms |
8012 KB |
Output is correct |
3 |
Correct |
6 ms |
8012 KB |
Output is correct |
4 |
Correct |
6 ms |
8140 KB |
Output is correct |
5 |
Correct |
7 ms |
8140 KB |
Output is correct |
6 |
Correct |
7 ms |
8236 KB |
Output is correct |
7 |
Correct |
7 ms |
8248 KB |
Output is correct |
8 |
Correct |
7 ms |
8144 KB |
Output is correct |
9 |
Correct |
6 ms |
8012 KB |
Output is correct |
10 |
Correct |
9 ms |
8244 KB |
Output is correct |
11 |
Correct |
7 ms |
8140 KB |
Output is correct |
12 |
Correct |
7 ms |
8140 KB |
Output is correct |
13 |
Correct |
7 ms |
8224 KB |
Output is correct |
14 |
Correct |
8 ms |
8232 KB |
Output is correct |
15 |
Correct |
7 ms |
8140 KB |
Output is correct |
16 |
Correct |
7 ms |
8156 KB |
Output is correct |
17 |
Correct |
7 ms |
8140 KB |
Output is correct |
18 |
Correct |
8 ms |
8140 KB |
Output is correct |
19 |
Correct |
8 ms |
8140 KB |
Output is correct |
20 |
Correct |
7 ms |
8140 KB |
Output is correct |
21 |
Correct |
9 ms |
8252 KB |
Output is correct |
22 |
Correct |
8 ms |
8312 KB |
Output is correct |
23 |
Correct |
8 ms |
8140 KB |
Output is correct |
24 |
Correct |
11 ms |
8268 KB |
Output is correct |
25 |
Correct |
11 ms |
8316 KB |
Output is correct |
26 |
Correct |
11 ms |
8268 KB |
Output is correct |
27 |
Correct |
7 ms |
8140 KB |
Output is correct |
28 |
Correct |
12 ms |
8276 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
8012 KB |
Output is correct |
2 |
Correct |
9 ms |
8012 KB |
Output is correct |
3 |
Correct |
5 ms |
8012 KB |
Output is correct |
4 |
Correct |
6 ms |
8012 KB |
Output is correct |
5 |
Correct |
6 ms |
8140 KB |
Output is correct |
6 |
Correct |
7 ms |
8140 KB |
Output is correct |
7 |
Correct |
7 ms |
8236 KB |
Output is correct |
8 |
Correct |
7 ms |
8248 KB |
Output is correct |
9 |
Correct |
7 ms |
8144 KB |
Output is correct |
10 |
Correct |
163 ms |
16532 KB |
Output is correct |
11 |
Correct |
240 ms |
18084 KB |
Output is correct |
12 |
Correct |
286 ms |
18860 KB |
Output is correct |
13 |
Correct |
429 ms |
19348 KB |
Output is correct |
14 |
Correct |
326 ms |
19292 KB |
Output is correct |
15 |
Correct |
9 ms |
8244 KB |
Output is correct |
16 |
Correct |
7 ms |
8140 KB |
Output is correct |
17 |
Correct |
7 ms |
8140 KB |
Output is correct |
18 |
Correct |
7 ms |
8224 KB |
Output is correct |
19 |
Correct |
8 ms |
8232 KB |
Output is correct |
20 |
Correct |
7 ms |
8140 KB |
Output is correct |
21 |
Correct |
7 ms |
8156 KB |
Output is correct |
22 |
Correct |
7 ms |
8140 KB |
Output is correct |
23 |
Correct |
8 ms |
8140 KB |
Output is correct |
24 |
Correct |
8 ms |
8140 KB |
Output is correct |
25 |
Correct |
7 ms |
8140 KB |
Output is correct |
26 |
Correct |
9 ms |
8252 KB |
Output is correct |
27 |
Correct |
8 ms |
8312 KB |
Output is correct |
28 |
Correct |
8 ms |
8140 KB |
Output is correct |
29 |
Correct |
11 ms |
8268 KB |
Output is correct |
30 |
Correct |
11 ms |
8316 KB |
Output is correct |
31 |
Correct |
11 ms |
8268 KB |
Output is correct |
32 |
Correct |
7 ms |
8140 KB |
Output is correct |
33 |
Correct |
12 ms |
8276 KB |
Output is correct |
34 |
Correct |
22 ms |
9972 KB |
Output is correct |
35 |
Correct |
371 ms |
18960 KB |
Output is correct |
36 |
Correct |
375 ms |
18476 KB |
Output is correct |
37 |
Correct |
412 ms |
18184 KB |
Output is correct |
38 |
Correct |
391 ms |
18056 KB |
Output is correct |
39 |
Correct |
448 ms |
18196 KB |
Output is correct |
40 |
Correct |
513 ms |
18248 KB |
Output is correct |
41 |
Correct |
412 ms |
18976 KB |
Output is correct |
42 |
Correct |
394 ms |
18836 KB |
Output is correct |
43 |
Correct |
367 ms |
18960 KB |
Output is correct |
44 |
Correct |
615 ms |
20108 KB |
Output is correct |
45 |
Correct |
881 ms |
25556 KB |
Output is correct |
46 |
Correct |
470 ms |
18580 KB |
Output is correct |
47 |
Correct |
552 ms |
18216 KB |
Output is correct |
48 |
Correct |
710 ms |
20404 KB |
Output is correct |
49 |
Correct |
116 ms |
24332 KB |
Output is correct |
50 |
Correct |
180 ms |
20256 KB |
Output is correct |
51 |
Correct |
752 ms |
23492 KB |
Output is correct |
52 |
Correct |
1051 ms |
26976 KB |
Output is correct |
53 |
Correct |
1073 ms |
28448 KB |
Output is correct |
54 |
Correct |
1232 ms |
30576 KB |
Output is correct |
55 |
Correct |
397 ms |
19736 KB |
Output is correct |
56 |
Correct |
1092 ms |
28348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
8012 KB |
Output is correct |
2 |
Correct |
5 ms |
8012 KB |
Output is correct |
3 |
Correct |
6 ms |
8012 KB |
Output is correct |
4 |
Correct |
6 ms |
8140 KB |
Output is correct |
5 |
Correct |
7 ms |
8140 KB |
Output is correct |
6 |
Correct |
7 ms |
8236 KB |
Output is correct |
7 |
Correct |
7 ms |
8248 KB |
Output is correct |
8 |
Correct |
7 ms |
8144 KB |
Output is correct |
9 |
Correct |
163 ms |
16532 KB |
Output is correct |
10 |
Correct |
240 ms |
18084 KB |
Output is correct |
11 |
Correct |
286 ms |
18860 KB |
Output is correct |
12 |
Correct |
429 ms |
19348 KB |
Output is correct |
13 |
Correct |
326 ms |
19292 KB |
Output is correct |
14 |
Execution timed out |
2077 ms |
17436 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
8012 KB |
Output is correct |
2 |
Correct |
9 ms |
8012 KB |
Output is correct |
3 |
Correct |
5 ms |
8012 KB |
Output is correct |
4 |
Correct |
6 ms |
8012 KB |
Output is correct |
5 |
Correct |
6 ms |
8140 KB |
Output is correct |
6 |
Correct |
7 ms |
8140 KB |
Output is correct |
7 |
Correct |
7 ms |
8236 KB |
Output is correct |
8 |
Correct |
7 ms |
8248 KB |
Output is correct |
9 |
Correct |
7 ms |
8144 KB |
Output is correct |
10 |
Correct |
163 ms |
16532 KB |
Output is correct |
11 |
Correct |
240 ms |
18084 KB |
Output is correct |
12 |
Correct |
286 ms |
18860 KB |
Output is correct |
13 |
Correct |
429 ms |
19348 KB |
Output is correct |
14 |
Correct |
326 ms |
19292 KB |
Output is correct |
15 |
Execution timed out |
2077 ms |
17436 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |