#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define endl '\n'
#define pb push_back
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ii = pair<int,int>;
using iii = tuple<int,int,int>;
const int inf = 2e9+1;
const int mod = 1e9+7;
const int maxn = 3e5+100;
template<typename X, typename Y> bool ckmin(X& x, const Y& y) { return (y < x) ? (x=y,1):0; }
template<typename X, typename Y> bool ckmax(X& x, const Y& y) { return (x < y) ? (x=y,1):0; }
vector<tuple<int,int,int>>edges;
int lvl[maxn], par[maxn], when[maxn];
ii pontas[maxn];
vector<int>comp[maxn];
vector<ii>parents[maxn];
int findp(int x){return par[x] = (par[x]==x?x:findp(par[x]));}
void merge(int w,int u,int v){
int pu = findp(u), pv = findp(v), ciclo = 0;
if(lvl[pu]<lvl[pv])swap(pu,pv), swap(u,v);
if(pu==pv)ciclo = 1;
//check if someone's component turned into a non-path component
par[pv] = pu;
if(when[pu]==inf&&when[pv]!=inf){
for(auto x:comp[pu])when[x] = w;
}else if(when[pu]!=inf&&when[pv]==inf){
for(auto x:comp[pv])when[x] = w;
}else if((ciclo||(u!=pontas[pu].first&&u!=pontas[pu].second)||
(v!=pontas[pv].first&&v!=pontas[pv].second))&&when[pu]==inf&&
when[pv]==inf){
for(auto x:comp[pu])when[x] = w;
if(!ciclo)for(auto x:comp[pv])when[x] = w;
}
if(ciclo)return;
for(auto x:comp[pv]){
comp[pu].pb(x);
parents[x].pb({w,pu});
}
if(when[pu]==when[pv]&&when[pu]==inf){
if(pontas[pu].first==u)swap(pontas[pu].first,pontas[pu].second);
if(pontas[pv].first!=v)pontas[pu].second = pontas[pv].first;
else pontas[pu].second = pontas[pv].second;
}
if(lvl[pu]==lvl[pv])++lvl[pu];
}
void init(int N, int M,vector<int> U, vector<int> V, vector<int> W) {
for(int i=0;i<M;++i){
edges.pb({W[i], U[i], V[i]});
}
for(int i=0;i<N;++i){
par[i] = i, pontas[i] = {i,i}, when[i] = inf;
parents[i].pb({0,i}), comp[i].pb(i);
}
sort(all(edges));
for(auto [w,u,v]:edges){
merge(w,u,v);
}
for(int i=0;i<N;++i)reverse(all(parents[i]));
}
int getMinimumFuelCapacity(int X, int Y) {
if(when[X]==inf)return -1;
int last = 0;
while(last!=min(sz(parents[X]), sz(parents[Y]))-1){
if(parents[X][last]!=parents[Y][last])break;
++last;
}
auto [custo,pai] = parents[X][last];
assert(pai==parents[Y][last].second);
ckmax(custo, parents[Y][last].first);
return max(custo, min(when[X], when[Y]));
}
// int main() {
// int N, M;
// assert(2 == scanf("%d %d", &N, &M));
// std::vector<int> U(M), V(M), W(M);
// for (int i = 0; i < M; ++i) {
// assert(3 == scanf("%d %d %d", &U[i], &V[i], &W[i]));
// }
// int Q;
// assert(1 == scanf("%d", &Q));
// std::vector<int> X(Q), Y(Q);
// for (int i = 0; i < Q; ++i) {
// assert(2 == scanf("%d %d", &X[i], &Y[i]));
// }
// init(N, M, U, V, W);
// std::vector<int> minimum_fuel_capacities(Q);
// for (int i = 0; i < Q; ++i) {
// minimum_fuel_capacities[i] = getMinimumFuelCapacity(X[i], Y[i]);
// }
// for (int i = 0; i < Q; ++i) {
// printf("%d\n", minimum_fuel_capacities[i]);
// }
// return 0;
// }
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
14420 KB |
Output is correct |
2 |
Correct |
8 ms |
14420 KB |
Output is correct |
3 |
Correct |
9 ms |
14336 KB |
Output is correct |
4 |
Correct |
9 ms |
14468 KB |
Output is correct |
5 |
Correct |
10 ms |
14536 KB |
Output is correct |
6 |
Correct |
9 ms |
14608 KB |
Output is correct |
7 |
Correct |
10 ms |
14604 KB |
Output is correct |
8 |
Correct |
9 ms |
14548 KB |
Output is correct |
9 |
Correct |
131 ms |
34828 KB |
Output is correct |
10 |
Correct |
218 ms |
39120 KB |
Output is correct |
11 |
Correct |
209 ms |
38084 KB |
Output is correct |
12 |
Correct |
219 ms |
39936 KB |
Output is correct |
13 |
Correct |
119 ms |
33116 KB |
Output is correct |
14 |
Correct |
145 ms |
34856 KB |
Output is correct |
15 |
Correct |
245 ms |
43852 KB |
Output is correct |
16 |
Correct |
239 ms |
42896 KB |
Output is correct |
17 |
Correct |
241 ms |
44488 KB |
Output is correct |
18 |
Correct |
173 ms |
37444 KB |
Output is correct |
19 |
Correct |
76 ms |
23252 KB |
Output is correct |
20 |
Correct |
253 ms |
44252 KB |
Output is correct |
21 |
Correct |
243 ms |
44024 KB |
Output is correct |
22 |
Correct |
250 ms |
45700 KB |
Output is correct |
23 |
Correct |
178 ms |
36292 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
14420 KB |
Output is correct |
2 |
Correct |
8 ms |
14420 KB |
Output is correct |
3 |
Runtime error |
152 ms |
58788 KB |
Execution killed with signal 6 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
14420 KB |
Output is correct |
2 |
Correct |
8 ms |
14420 KB |
Output is correct |
3 |
Correct |
9 ms |
14336 KB |
Output is correct |
4 |
Correct |
9 ms |
14468 KB |
Output is correct |
5 |
Correct |
10 ms |
14536 KB |
Output is correct |
6 |
Correct |
9 ms |
14608 KB |
Output is correct |
7 |
Correct |
10 ms |
14604 KB |
Output is correct |
8 |
Correct |
9 ms |
14548 KB |
Output is correct |
9 |
Correct |
9 ms |
14420 KB |
Output is correct |
10 |
Correct |
11 ms |
14532 KB |
Output is correct |
11 |
Correct |
8 ms |
14548 KB |
Output is correct |
12 |
Correct |
9 ms |
14548 KB |
Output is correct |
13 |
Correct |
9 ms |
14548 KB |
Output is correct |
14 |
Correct |
9 ms |
14548 KB |
Output is correct |
15 |
Correct |
11 ms |
14588 KB |
Output is correct |
16 |
Correct |
10 ms |
14540 KB |
Output is correct |
17 |
Correct |
11 ms |
14548 KB |
Output is correct |
18 |
Correct |
9 ms |
14564 KB |
Output is correct |
19 |
Correct |
9 ms |
14552 KB |
Output is correct |
20 |
Correct |
9 ms |
14532 KB |
Output is correct |
21 |
Correct |
9 ms |
14544 KB |
Output is correct |
22 |
Correct |
9 ms |
14420 KB |
Output is correct |
23 |
Correct |
8 ms |
14540 KB |
Output is correct |
24 |
Correct |
10 ms |
14632 KB |
Output is correct |
25 |
Correct |
9 ms |
14564 KB |
Output is correct |
26 |
Correct |
11 ms |
14664 KB |
Output is correct |
27 |
Correct |
10 ms |
14548 KB |
Output is correct |
28 |
Correct |
9 ms |
14584 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
14420 KB |
Output is correct |
2 |
Correct |
8 ms |
14420 KB |
Output is correct |
3 |
Correct |
8 ms |
14420 KB |
Output is correct |
4 |
Correct |
9 ms |
14336 KB |
Output is correct |
5 |
Correct |
9 ms |
14468 KB |
Output is correct |
6 |
Correct |
10 ms |
14536 KB |
Output is correct |
7 |
Correct |
9 ms |
14608 KB |
Output is correct |
8 |
Correct |
10 ms |
14604 KB |
Output is correct |
9 |
Correct |
9 ms |
14548 KB |
Output is correct |
10 |
Correct |
131 ms |
34828 KB |
Output is correct |
11 |
Correct |
218 ms |
39120 KB |
Output is correct |
12 |
Correct |
209 ms |
38084 KB |
Output is correct |
13 |
Correct |
219 ms |
39936 KB |
Output is correct |
14 |
Correct |
119 ms |
33116 KB |
Output is correct |
15 |
Correct |
11 ms |
14532 KB |
Output is correct |
16 |
Correct |
8 ms |
14548 KB |
Output is correct |
17 |
Correct |
9 ms |
14548 KB |
Output is correct |
18 |
Correct |
9 ms |
14548 KB |
Output is correct |
19 |
Correct |
9 ms |
14548 KB |
Output is correct |
20 |
Correct |
11 ms |
14588 KB |
Output is correct |
21 |
Correct |
10 ms |
14540 KB |
Output is correct |
22 |
Correct |
11 ms |
14548 KB |
Output is correct |
23 |
Correct |
9 ms |
14564 KB |
Output is correct |
24 |
Correct |
9 ms |
14552 KB |
Output is correct |
25 |
Correct |
9 ms |
14532 KB |
Output is correct |
26 |
Correct |
9 ms |
14544 KB |
Output is correct |
27 |
Correct |
9 ms |
14420 KB |
Output is correct |
28 |
Correct |
8 ms |
14540 KB |
Output is correct |
29 |
Correct |
10 ms |
14632 KB |
Output is correct |
30 |
Correct |
9 ms |
14564 KB |
Output is correct |
31 |
Correct |
11 ms |
14664 KB |
Output is correct |
32 |
Correct |
10 ms |
14548 KB |
Output is correct |
33 |
Correct |
9 ms |
14584 KB |
Output is correct |
34 |
Correct |
25 ms |
17320 KB |
Output is correct |
35 |
Correct |
208 ms |
40116 KB |
Output is correct |
36 |
Correct |
183 ms |
39356 KB |
Output is correct |
37 |
Correct |
232 ms |
38332 KB |
Output is correct |
38 |
Correct |
182 ms |
37272 KB |
Output is correct |
39 |
Correct |
201 ms |
37424 KB |
Output is correct |
40 |
Correct |
169 ms |
34744 KB |
Output is correct |
41 |
Correct |
198 ms |
40488 KB |
Output is correct |
42 |
Correct |
192 ms |
40252 KB |
Output is correct |
43 |
Correct |
117 ms |
31676 KB |
Output is correct |
44 |
Correct |
201 ms |
37692 KB |
Output is correct |
45 |
Correct |
134 ms |
32324 KB |
Output is correct |
46 |
Correct |
182 ms |
39476 KB |
Output is correct |
47 |
Correct |
192 ms |
35272 KB |
Output is correct |
48 |
Correct |
156 ms |
32196 KB |
Output is correct |
49 |
Correct |
74 ms |
24048 KB |
Output is correct |
50 |
Correct |
62 ms |
21808 KB |
Output is correct |
51 |
Correct |
101 ms |
29360 KB |
Output is correct |
52 |
Correct |
216 ms |
41732 KB |
Output is correct |
53 |
Correct |
191 ms |
37588 KB |
Output is correct |
54 |
Correct |
279 ms |
45344 KB |
Output is correct |
55 |
Correct |
136 ms |
30268 KB |
Output is correct |
56 |
Correct |
170 ms |
36252 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
14420 KB |
Output is correct |
2 |
Correct |
8 ms |
14420 KB |
Output is correct |
3 |
Correct |
9 ms |
14336 KB |
Output is correct |
4 |
Correct |
9 ms |
14468 KB |
Output is correct |
5 |
Correct |
10 ms |
14536 KB |
Output is correct |
6 |
Correct |
9 ms |
14608 KB |
Output is correct |
7 |
Correct |
10 ms |
14604 KB |
Output is correct |
8 |
Correct |
9 ms |
14548 KB |
Output is correct |
9 |
Correct |
131 ms |
34828 KB |
Output is correct |
10 |
Correct |
218 ms |
39120 KB |
Output is correct |
11 |
Correct |
209 ms |
38084 KB |
Output is correct |
12 |
Correct |
219 ms |
39936 KB |
Output is correct |
13 |
Correct |
119 ms |
33116 KB |
Output is correct |
14 |
Correct |
145 ms |
34856 KB |
Output is correct |
15 |
Correct |
245 ms |
43852 KB |
Output is correct |
16 |
Correct |
239 ms |
42896 KB |
Output is correct |
17 |
Correct |
241 ms |
44488 KB |
Output is correct |
18 |
Correct |
173 ms |
37444 KB |
Output is correct |
19 |
Runtime error |
152 ms |
58788 KB |
Execution killed with signal 6 |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
14420 KB |
Output is correct |
2 |
Correct |
8 ms |
14420 KB |
Output is correct |
3 |
Correct |
8 ms |
14420 KB |
Output is correct |
4 |
Correct |
9 ms |
14336 KB |
Output is correct |
5 |
Correct |
9 ms |
14468 KB |
Output is correct |
6 |
Correct |
10 ms |
14536 KB |
Output is correct |
7 |
Correct |
9 ms |
14608 KB |
Output is correct |
8 |
Correct |
10 ms |
14604 KB |
Output is correct |
9 |
Correct |
9 ms |
14548 KB |
Output is correct |
10 |
Correct |
131 ms |
34828 KB |
Output is correct |
11 |
Correct |
218 ms |
39120 KB |
Output is correct |
12 |
Correct |
209 ms |
38084 KB |
Output is correct |
13 |
Correct |
219 ms |
39936 KB |
Output is correct |
14 |
Correct |
119 ms |
33116 KB |
Output is correct |
15 |
Correct |
145 ms |
34856 KB |
Output is correct |
16 |
Correct |
245 ms |
43852 KB |
Output is correct |
17 |
Correct |
239 ms |
42896 KB |
Output is correct |
18 |
Correct |
241 ms |
44488 KB |
Output is correct |
19 |
Correct |
173 ms |
37444 KB |
Output is correct |
20 |
Runtime error |
152 ms |
58788 KB |
Execution killed with signal 6 |
21 |
Halted |
0 ms |
0 KB |
- |