#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 = 1e5+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];
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;
// }
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
4 ms |
5076 KB |
Output is correct |
5 |
Correct |
4 ms |
5116 KB |
Output is correct |
6 |
Correct |
4 ms |
5204 KB |
Output is correct |
7 |
Correct |
4 ms |
5204 KB |
Output is correct |
8 |
Correct |
4 ms |
5076 KB |
Output is correct |
9 |
Correct |
124 ms |
23720 KB |
Output is correct |
10 |
Correct |
210 ms |
27712 KB |
Output is correct |
11 |
Correct |
161 ms |
26756 KB |
Output is correct |
12 |
Correct |
215 ms |
28444 KB |
Output is correct |
13 |
Correct |
109 ms |
21524 KB |
Output is correct |
14 |
Correct |
144 ms |
23540 KB |
Output is correct |
15 |
Correct |
266 ms |
30120 KB |
Output is correct |
16 |
Correct |
223 ms |
29188 KB |
Output is correct |
17 |
Correct |
269 ms |
30608 KB |
Output is correct |
18 |
Correct |
167 ms |
23584 KB |
Output is correct |
19 |
Correct |
65 ms |
11788 KB |
Output is correct |
20 |
Correct |
273 ms |
30596 KB |
Output is correct |
21 |
Correct |
224 ms |
30364 KB |
Output is correct |
22 |
Correct |
280 ms |
31844 KB |
Output is correct |
23 |
Correct |
172 ms |
22488 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
159 ms |
19588 KB |
Output is correct |
4 |
Correct |
163 ms |
23888 KB |
Output is correct |
5 |
Correct |
170 ms |
24012 KB |
Output is correct |
6 |
Correct |
170 ms |
23720 KB |
Output is correct |
7 |
Correct |
163 ms |
24048 KB |
Output is correct |
8 |
Correct |
160 ms |
23396 KB |
Output is correct |
9 |
Correct |
168 ms |
23744 KB |
Output is correct |
10 |
Correct |
165 ms |
23416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
4 ms |
5076 KB |
Output is correct |
5 |
Correct |
4 ms |
5116 KB |
Output is correct |
6 |
Correct |
4 ms |
5204 KB |
Output is correct |
7 |
Correct |
4 ms |
5204 KB |
Output is correct |
8 |
Correct |
4 ms |
5076 KB |
Output is correct |
9 |
Correct |
3 ms |
5028 KB |
Output is correct |
10 |
Correct |
3 ms |
5076 KB |
Output is correct |
11 |
Correct |
4 ms |
5204 KB |
Output is correct |
12 |
Correct |
4 ms |
5204 KB |
Output is correct |
13 |
Correct |
4 ms |
5076 KB |
Output is correct |
14 |
Correct |
3 ms |
5148 KB |
Output is correct |
15 |
Correct |
4 ms |
5204 KB |
Output is correct |
16 |
Correct |
5 ms |
5156 KB |
Output is correct |
17 |
Correct |
3 ms |
5184 KB |
Output is correct |
18 |
Correct |
4 ms |
5152 KB |
Output is correct |
19 |
Correct |
3 ms |
5076 KB |
Output is correct |
20 |
Correct |
3 ms |
5204 KB |
Output is correct |
21 |
Correct |
3 ms |
5076 KB |
Output is correct |
22 |
Correct |
4 ms |
5076 KB |
Output is correct |
23 |
Correct |
3 ms |
5076 KB |
Output is correct |
24 |
Correct |
4 ms |
5204 KB |
Output is correct |
25 |
Correct |
4 ms |
5228 KB |
Output is correct |
26 |
Correct |
4 ms |
5204 KB |
Output is correct |
27 |
Correct |
4 ms |
5076 KB |
Output is correct |
28 |
Correct |
4 ms |
5204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
5028 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
4 ms |
5076 KB |
Output is correct |
6 |
Correct |
4 ms |
5116 KB |
Output is correct |
7 |
Correct |
4 ms |
5204 KB |
Output is correct |
8 |
Correct |
4 ms |
5204 KB |
Output is correct |
9 |
Correct |
4 ms |
5076 KB |
Output is correct |
10 |
Correct |
124 ms |
23720 KB |
Output is correct |
11 |
Correct |
210 ms |
27712 KB |
Output is correct |
12 |
Correct |
161 ms |
26756 KB |
Output is correct |
13 |
Correct |
215 ms |
28444 KB |
Output is correct |
14 |
Correct |
109 ms |
21524 KB |
Output is correct |
15 |
Correct |
3 ms |
5076 KB |
Output is correct |
16 |
Correct |
4 ms |
5204 KB |
Output is correct |
17 |
Correct |
4 ms |
5204 KB |
Output is correct |
18 |
Correct |
4 ms |
5076 KB |
Output is correct |
19 |
Correct |
3 ms |
5148 KB |
Output is correct |
20 |
Correct |
4 ms |
5204 KB |
Output is correct |
21 |
Correct |
5 ms |
5156 KB |
Output is correct |
22 |
Correct |
3 ms |
5184 KB |
Output is correct |
23 |
Correct |
4 ms |
5152 KB |
Output is correct |
24 |
Correct |
3 ms |
5076 KB |
Output is correct |
25 |
Correct |
3 ms |
5204 KB |
Output is correct |
26 |
Correct |
3 ms |
5076 KB |
Output is correct |
27 |
Correct |
4 ms |
5076 KB |
Output is correct |
28 |
Correct |
3 ms |
5076 KB |
Output is correct |
29 |
Correct |
4 ms |
5204 KB |
Output is correct |
30 |
Correct |
4 ms |
5228 KB |
Output is correct |
31 |
Correct |
4 ms |
5204 KB |
Output is correct |
32 |
Correct |
4 ms |
5076 KB |
Output is correct |
33 |
Correct |
4 ms |
5204 KB |
Output is correct |
34 |
Correct |
15 ms |
7700 KB |
Output is correct |
35 |
Correct |
203 ms |
28880 KB |
Output is correct |
36 |
Correct |
189 ms |
28096 KB |
Output is correct |
37 |
Correct |
175 ms |
27168 KB |
Output is correct |
38 |
Correct |
165 ms |
26064 KB |
Output is correct |
39 |
Correct |
186 ms |
26304 KB |
Output is correct |
40 |
Correct |
158 ms |
23636 KB |
Output is correct |
41 |
Correct |
197 ms |
28972 KB |
Output is correct |
42 |
Correct |
173 ms |
29036 KB |
Output is correct |
43 |
Correct |
119 ms |
20352 KB |
Output is correct |
44 |
Correct |
164 ms |
26148 KB |
Output is correct |
45 |
Correct |
145 ms |
19932 KB |
Output is correct |
46 |
Correct |
193 ms |
28328 KB |
Output is correct |
47 |
Correct |
176 ms |
23968 KB |
Output is correct |
48 |
Correct |
117 ms |
20820 KB |
Output is correct |
49 |
Correct |
64 ms |
11852 KB |
Output is correct |
50 |
Correct |
52 ms |
10124 KB |
Output is correct |
51 |
Correct |
107 ms |
17224 KB |
Output is correct |
52 |
Correct |
203 ms |
28900 KB |
Output is correct |
53 |
Correct |
176 ms |
24492 KB |
Output is correct |
54 |
Correct |
260 ms |
31924 KB |
Output is correct |
55 |
Correct |
116 ms |
19008 KB |
Output is correct |
56 |
Correct |
182 ms |
23272 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
4 ms |
5076 KB |
Output is correct |
5 |
Correct |
4 ms |
5116 KB |
Output is correct |
6 |
Correct |
4 ms |
5204 KB |
Output is correct |
7 |
Correct |
4 ms |
5204 KB |
Output is correct |
8 |
Correct |
4 ms |
5076 KB |
Output is correct |
9 |
Correct |
124 ms |
23720 KB |
Output is correct |
10 |
Correct |
210 ms |
27712 KB |
Output is correct |
11 |
Correct |
161 ms |
26756 KB |
Output is correct |
12 |
Correct |
215 ms |
28444 KB |
Output is correct |
13 |
Correct |
109 ms |
21524 KB |
Output is correct |
14 |
Correct |
144 ms |
23540 KB |
Output is correct |
15 |
Correct |
266 ms |
30120 KB |
Output is correct |
16 |
Correct |
223 ms |
29188 KB |
Output is correct |
17 |
Correct |
269 ms |
30608 KB |
Output is correct |
18 |
Correct |
167 ms |
23584 KB |
Output is correct |
19 |
Correct |
159 ms |
19588 KB |
Output is correct |
20 |
Correct |
163 ms |
23888 KB |
Output is correct |
21 |
Correct |
170 ms |
24012 KB |
Output is correct |
22 |
Correct |
170 ms |
23720 KB |
Output is correct |
23 |
Correct |
163 ms |
24048 KB |
Output is correct |
24 |
Correct |
160 ms |
23396 KB |
Output is correct |
25 |
Correct |
168 ms |
23744 KB |
Output is correct |
26 |
Correct |
165 ms |
23416 KB |
Output is correct |
27 |
Correct |
3 ms |
5076 KB |
Output is correct |
28 |
Correct |
4 ms |
5204 KB |
Output is correct |
29 |
Correct |
4 ms |
5204 KB |
Output is correct |
30 |
Correct |
4 ms |
5076 KB |
Output is correct |
31 |
Correct |
3 ms |
5148 KB |
Output is correct |
32 |
Correct |
4 ms |
5204 KB |
Output is correct |
33 |
Correct |
5 ms |
5156 KB |
Output is correct |
34 |
Correct |
3 ms |
5184 KB |
Output is correct |
35 |
Correct |
4 ms |
5152 KB |
Output is correct |
36 |
Correct |
15 ms |
7700 KB |
Output is correct |
37 |
Correct |
203 ms |
28880 KB |
Output is correct |
38 |
Correct |
189 ms |
28096 KB |
Output is correct |
39 |
Correct |
175 ms |
27168 KB |
Output is correct |
40 |
Correct |
165 ms |
26064 KB |
Output is correct |
41 |
Correct |
186 ms |
26304 KB |
Output is correct |
42 |
Correct |
158 ms |
23636 KB |
Output is correct |
43 |
Correct |
197 ms |
28972 KB |
Output is correct |
44 |
Correct |
173 ms |
29036 KB |
Output is correct |
45 |
Correct |
119 ms |
20352 KB |
Output is correct |
46 |
Correct |
164 ms |
26148 KB |
Output is correct |
47 |
Correct |
20 ms |
8272 KB |
Output is correct |
48 |
Correct |
296 ms |
34828 KB |
Output is correct |
49 |
Correct |
290 ms |
35484 KB |
Output is correct |
50 |
Correct |
264 ms |
34160 KB |
Output is correct |
51 |
Incorrect |
285 ms |
33520 KB |
Output isn't correct |
52 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
5028 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
4 ms |
5076 KB |
Output is correct |
6 |
Correct |
4 ms |
5116 KB |
Output is correct |
7 |
Correct |
4 ms |
5204 KB |
Output is correct |
8 |
Correct |
4 ms |
5204 KB |
Output is correct |
9 |
Correct |
4 ms |
5076 KB |
Output is correct |
10 |
Correct |
124 ms |
23720 KB |
Output is correct |
11 |
Correct |
210 ms |
27712 KB |
Output is correct |
12 |
Correct |
161 ms |
26756 KB |
Output is correct |
13 |
Correct |
215 ms |
28444 KB |
Output is correct |
14 |
Correct |
109 ms |
21524 KB |
Output is correct |
15 |
Correct |
144 ms |
23540 KB |
Output is correct |
16 |
Correct |
266 ms |
30120 KB |
Output is correct |
17 |
Correct |
223 ms |
29188 KB |
Output is correct |
18 |
Correct |
269 ms |
30608 KB |
Output is correct |
19 |
Correct |
167 ms |
23584 KB |
Output is correct |
20 |
Correct |
159 ms |
19588 KB |
Output is correct |
21 |
Correct |
163 ms |
23888 KB |
Output is correct |
22 |
Correct |
170 ms |
24012 KB |
Output is correct |
23 |
Correct |
170 ms |
23720 KB |
Output is correct |
24 |
Correct |
163 ms |
24048 KB |
Output is correct |
25 |
Correct |
160 ms |
23396 KB |
Output is correct |
26 |
Correct |
168 ms |
23744 KB |
Output is correct |
27 |
Correct |
165 ms |
23416 KB |
Output is correct |
28 |
Correct |
3 ms |
5076 KB |
Output is correct |
29 |
Correct |
4 ms |
5204 KB |
Output is correct |
30 |
Correct |
4 ms |
5204 KB |
Output is correct |
31 |
Correct |
4 ms |
5076 KB |
Output is correct |
32 |
Correct |
3 ms |
5148 KB |
Output is correct |
33 |
Correct |
4 ms |
5204 KB |
Output is correct |
34 |
Correct |
5 ms |
5156 KB |
Output is correct |
35 |
Correct |
3 ms |
5184 KB |
Output is correct |
36 |
Correct |
4 ms |
5152 KB |
Output is correct |
37 |
Correct |
15 ms |
7700 KB |
Output is correct |
38 |
Correct |
203 ms |
28880 KB |
Output is correct |
39 |
Correct |
189 ms |
28096 KB |
Output is correct |
40 |
Correct |
175 ms |
27168 KB |
Output is correct |
41 |
Correct |
165 ms |
26064 KB |
Output is correct |
42 |
Correct |
186 ms |
26304 KB |
Output is correct |
43 |
Correct |
158 ms |
23636 KB |
Output is correct |
44 |
Correct |
197 ms |
28972 KB |
Output is correct |
45 |
Correct |
173 ms |
29036 KB |
Output is correct |
46 |
Correct |
119 ms |
20352 KB |
Output is correct |
47 |
Correct |
164 ms |
26148 KB |
Output is correct |
48 |
Correct |
20 ms |
8272 KB |
Output is correct |
49 |
Correct |
296 ms |
34828 KB |
Output is correct |
50 |
Correct |
290 ms |
35484 KB |
Output is correct |
51 |
Correct |
264 ms |
34160 KB |
Output is correct |
52 |
Incorrect |
285 ms |
33520 KB |
Output isn't correct |
53 |
Halted |
0 ms |
0 KB |
- |