// #pragma GCC target ("avx,avx2,fma")
// #pragma GCC optimize ("Ofast,inline") // O1 - O2 - O3 - Os - Ofast
// #pragma GCC optimize ("unroll-loops")
#include "swap.h"
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define per(i, a, b) for (int i = (b - 1); i >= (a); --i)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()
#define sz(x) x.size()
#define pb push_back
#define debug(x) cout << #x << " = " << x << endl
#define umap unordered_map
#define uset unordered_set
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
const int INF = 1'000'000'007;
struct ufds_rollback {
vector<vii>p;
vi rank,max_deg,possible,deg;
vector<bool>cycle;
ufds_rollback(int n) {
deg.assign(n,0);
rank.assign(n,0);
cycle.assign(n,0);
max_deg.assign(n,0);
possible.assign(n,INF);
p.resize(n);
rep(i,0,n)p[i].emplace_back(0,i);
}
int find(int i,const int &mx) {
auto it=upper_bound(all(p[i]),ii(mx,INF));
--it;
//cout<<"i = "<<i<<" mx = "<<mx<<" val = "<<it->first<<" p = "<<it->second<<endl;
if(it->second==i)return i;
else return find(it->second,mx);
return 0;
}
void union_set(int i,int j,int val) {
int u=find(i,val);
int v=find(j,val);
if(u==v) {
cycle[u]=1;
possible[u]=min(possible[u],val);
return;
}
++deg[i];
++deg[j];
max_deg[u]=max(max_deg[u],deg[i]);
max_deg[v]=max(max_deg[v],deg[j]);
if(rank[u]<rank[v])swap(u,v);
if(rank[u]==rank[v])++rank[u];
if(p[v].back().first==val)p[v].pop_back();
p[v].emplace_back(val,u);
max_deg[u]=max(max_deg[u],max_deg[v]);
if(possible[v]!=INF||max_deg[u]>=3) possible[u]=min(possible[u],val);
}
};
ufds_rollback ufds(100001);
vector<iii> edges;
int n,m;
void init(int N, int M, std::vector<int> U, std::vector<int> V, std::vector<int> W) {
n=N;
m=M;
rep(i,0,m) edges.pb({W[i],{U[i],V[i]}});
sort(all(edges));
//rep(i,0,n) {
// auto it=ufds.p[i].begin();
// cout<<sz(ufds.p[i])<<' '<<it->first<<' '<<it->second<<' ';
// ufds.find(i,0);
//}
trav(edge,edges) {
int u,v,w;
w=edge.first;
tie(u,v)=edge.second;
ufds.union_set(u,v,w);
//cout<<"u = "<<u<<" v = "<<v<<" w = "<<w<<endl;
}
edges.pb({-1,{0,0}});
}
int getMinimumFuelCapacity(int X, int Y) {
int u=X,v=Y;
int lo=0,hi=m;
while(lo!=hi) {
int mid=(lo+hi)/2;
int w=edges[mid].first;
int p=ufds.find(u,w);
if(p==ufds.find(v,w)&&ufds.possible[p]<=w) hi=mid;
else lo=mid+1;
}
return edges[lo].first;
}
/*
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 |
6 ms |
7244 KB |
Output is correct |
2 |
Correct |
6 ms |
7244 KB |
Output is correct |
3 |
Correct |
6 ms |
7244 KB |
Output is correct |
4 |
Correct |
6 ms |
7372 KB |
Output is correct |
5 |
Correct |
6 ms |
7372 KB |
Output is correct |
6 |
Correct |
6 ms |
7372 KB |
Output is correct |
7 |
Correct |
6 ms |
7372 KB |
Output is correct |
8 |
Correct |
6 ms |
7372 KB |
Output is correct |
9 |
Correct |
45 ms |
10848 KB |
Output is correct |
10 |
Correct |
60 ms |
11168 KB |
Output is correct |
11 |
Correct |
56 ms |
11160 KB |
Output is correct |
12 |
Correct |
66 ms |
11352 KB |
Output is correct |
13 |
Correct |
58 ms |
11340 KB |
Output is correct |
14 |
Correct |
70 ms |
10948 KB |
Output is correct |
15 |
Correct |
364 ms |
12856 KB |
Output is correct |
16 |
Correct |
401 ms |
12772 KB |
Output is correct |
17 |
Correct |
366 ms |
12880 KB |
Output is correct |
18 |
Correct |
188 ms |
12916 KB |
Output is correct |
19 |
Correct |
185 ms |
13428 KB |
Output is correct |
20 |
Correct |
376 ms |
17824 KB |
Output is correct |
21 |
Correct |
389 ms |
18236 KB |
Output is correct |
22 |
Correct |
366 ms |
18528 KB |
Output is correct |
23 |
Correct |
197 ms |
18580 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
7244 KB |
Output is correct |
2 |
Correct |
6 ms |
7244 KB |
Output is correct |
3 |
Correct |
215 ms |
13624 KB |
Output is correct |
4 |
Correct |
212 ms |
13780 KB |
Output is correct |
5 |
Correct |
218 ms |
14024 KB |
Output is correct |
6 |
Correct |
200 ms |
13604 KB |
Output is correct |
7 |
Correct |
223 ms |
13888 KB |
Output is correct |
8 |
Correct |
194 ms |
13752 KB |
Output is correct |
9 |
Correct |
183 ms |
13692 KB |
Output is correct |
10 |
Correct |
206 ms |
13752 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
7244 KB |
Output is correct |
2 |
Correct |
6 ms |
7244 KB |
Output is correct |
3 |
Correct |
6 ms |
7244 KB |
Output is correct |
4 |
Correct |
6 ms |
7372 KB |
Output is correct |
5 |
Correct |
6 ms |
7372 KB |
Output is correct |
6 |
Correct |
6 ms |
7372 KB |
Output is correct |
7 |
Correct |
6 ms |
7372 KB |
Output is correct |
8 |
Correct |
6 ms |
7372 KB |
Output is correct |
9 |
Correct |
9 ms |
7244 KB |
Output is correct |
10 |
Correct |
6 ms |
7348 KB |
Output is correct |
11 |
Correct |
6 ms |
7372 KB |
Output is correct |
12 |
Correct |
7 ms |
7372 KB |
Output is correct |
13 |
Correct |
6 ms |
7372 KB |
Output is correct |
14 |
Correct |
6 ms |
7372 KB |
Output is correct |
15 |
Correct |
6 ms |
7372 KB |
Output is correct |
16 |
Correct |
6 ms |
7284 KB |
Output is correct |
17 |
Correct |
6 ms |
7372 KB |
Output is correct |
18 |
Correct |
6 ms |
7348 KB |
Output is correct |
19 |
Correct |
10 ms |
7388 KB |
Output is correct |
20 |
Correct |
8 ms |
7320 KB |
Output is correct |
21 |
Correct |
7 ms |
7408 KB |
Output is correct |
22 |
Correct |
10 ms |
7372 KB |
Output is correct |
23 |
Correct |
9 ms |
7372 KB |
Output is correct |
24 |
Correct |
7 ms |
7372 KB |
Output is correct |
25 |
Correct |
9 ms |
7368 KB |
Output is correct |
26 |
Correct |
8 ms |
7372 KB |
Output is correct |
27 |
Correct |
8 ms |
7320 KB |
Output is correct |
28 |
Correct |
7 ms |
7372 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
7244 KB |
Output is correct |
2 |
Correct |
6 ms |
7244 KB |
Output is correct |
3 |
Correct |
6 ms |
7244 KB |
Output is correct |
4 |
Correct |
6 ms |
7244 KB |
Output is correct |
5 |
Correct |
6 ms |
7372 KB |
Output is correct |
6 |
Correct |
6 ms |
7372 KB |
Output is correct |
7 |
Correct |
6 ms |
7372 KB |
Output is correct |
8 |
Correct |
6 ms |
7372 KB |
Output is correct |
9 |
Correct |
6 ms |
7372 KB |
Output is correct |
10 |
Correct |
45 ms |
10848 KB |
Output is correct |
11 |
Correct |
60 ms |
11168 KB |
Output is correct |
12 |
Correct |
56 ms |
11160 KB |
Output is correct |
13 |
Correct |
66 ms |
11352 KB |
Output is correct |
14 |
Correct |
58 ms |
11340 KB |
Output is correct |
15 |
Correct |
6 ms |
7348 KB |
Output is correct |
16 |
Correct |
6 ms |
7372 KB |
Output is correct |
17 |
Correct |
7 ms |
7372 KB |
Output is correct |
18 |
Correct |
6 ms |
7372 KB |
Output is correct |
19 |
Correct |
6 ms |
7372 KB |
Output is correct |
20 |
Correct |
6 ms |
7372 KB |
Output is correct |
21 |
Correct |
6 ms |
7284 KB |
Output is correct |
22 |
Correct |
6 ms |
7372 KB |
Output is correct |
23 |
Correct |
6 ms |
7348 KB |
Output is correct |
24 |
Correct |
10 ms |
7388 KB |
Output is correct |
25 |
Correct |
8 ms |
7320 KB |
Output is correct |
26 |
Correct |
7 ms |
7408 KB |
Output is correct |
27 |
Correct |
10 ms |
7372 KB |
Output is correct |
28 |
Correct |
9 ms |
7372 KB |
Output is correct |
29 |
Correct |
7 ms |
7372 KB |
Output is correct |
30 |
Correct |
9 ms |
7368 KB |
Output is correct |
31 |
Correct |
8 ms |
7372 KB |
Output is correct |
32 |
Correct |
8 ms |
7320 KB |
Output is correct |
33 |
Correct |
7 ms |
7372 KB |
Output is correct |
34 |
Correct |
13 ms |
7948 KB |
Output is correct |
35 |
Correct |
68 ms |
11344 KB |
Output is correct |
36 |
Correct |
81 ms |
11328 KB |
Output is correct |
37 |
Correct |
88 ms |
11348 KB |
Output is correct |
38 |
Correct |
65 ms |
11344 KB |
Output is correct |
39 |
Correct |
56 ms |
11332 KB |
Output is correct |
40 |
Correct |
64 ms |
11040 KB |
Output is correct |
41 |
Correct |
59 ms |
11328 KB |
Output is correct |
42 |
Correct |
71 ms |
11356 KB |
Output is correct |
43 |
Correct |
68 ms |
11332 KB |
Output is correct |
44 |
Correct |
62 ms |
11348 KB |
Output is correct |
45 |
Correct |
89 ms |
13948 KB |
Output is correct |
46 |
Correct |
63 ms |
13120 KB |
Output is correct |
47 |
Correct |
88 ms |
13112 KB |
Output is correct |
48 |
Correct |
63 ms |
13628 KB |
Output is correct |
49 |
Correct |
71 ms |
17000 KB |
Output is correct |
50 |
Correct |
56 ms |
14140 KB |
Output is correct |
51 |
Correct |
68 ms |
14732 KB |
Output is correct |
52 |
Correct |
151 ms |
17680 KB |
Output is correct |
53 |
Correct |
111 ms |
18516 KB |
Output is correct |
54 |
Correct |
128 ms |
19136 KB |
Output is correct |
55 |
Correct |
61 ms |
13128 KB |
Output is correct |
56 |
Correct |
122 ms |
18180 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
7244 KB |
Output is correct |
2 |
Correct |
6 ms |
7244 KB |
Output is correct |
3 |
Correct |
6 ms |
7244 KB |
Output is correct |
4 |
Correct |
6 ms |
7372 KB |
Output is correct |
5 |
Correct |
6 ms |
7372 KB |
Output is correct |
6 |
Correct |
6 ms |
7372 KB |
Output is correct |
7 |
Correct |
6 ms |
7372 KB |
Output is correct |
8 |
Correct |
6 ms |
7372 KB |
Output is correct |
9 |
Correct |
45 ms |
10848 KB |
Output is correct |
10 |
Correct |
60 ms |
11168 KB |
Output is correct |
11 |
Correct |
56 ms |
11160 KB |
Output is correct |
12 |
Correct |
66 ms |
11352 KB |
Output is correct |
13 |
Correct |
58 ms |
11340 KB |
Output is correct |
14 |
Correct |
70 ms |
10948 KB |
Output is correct |
15 |
Correct |
364 ms |
12856 KB |
Output is correct |
16 |
Correct |
401 ms |
12772 KB |
Output is correct |
17 |
Correct |
366 ms |
12880 KB |
Output is correct |
18 |
Correct |
188 ms |
12916 KB |
Output is correct |
19 |
Correct |
215 ms |
13624 KB |
Output is correct |
20 |
Correct |
212 ms |
13780 KB |
Output is correct |
21 |
Correct |
218 ms |
14024 KB |
Output is correct |
22 |
Correct |
200 ms |
13604 KB |
Output is correct |
23 |
Correct |
223 ms |
13888 KB |
Output is correct |
24 |
Correct |
194 ms |
13752 KB |
Output is correct |
25 |
Correct |
183 ms |
13692 KB |
Output is correct |
26 |
Correct |
206 ms |
13752 KB |
Output is correct |
27 |
Correct |
6 ms |
7348 KB |
Output is correct |
28 |
Correct |
6 ms |
7372 KB |
Output is correct |
29 |
Correct |
7 ms |
7372 KB |
Output is correct |
30 |
Correct |
6 ms |
7372 KB |
Output is correct |
31 |
Correct |
6 ms |
7372 KB |
Output is correct |
32 |
Correct |
6 ms |
7372 KB |
Output is correct |
33 |
Correct |
6 ms |
7284 KB |
Output is correct |
34 |
Correct |
6 ms |
7372 KB |
Output is correct |
35 |
Correct |
6 ms |
7348 KB |
Output is correct |
36 |
Correct |
13 ms |
7948 KB |
Output is correct |
37 |
Correct |
68 ms |
11344 KB |
Output is correct |
38 |
Correct |
81 ms |
11328 KB |
Output is correct |
39 |
Correct |
88 ms |
11348 KB |
Output is correct |
40 |
Correct |
65 ms |
11344 KB |
Output is correct |
41 |
Correct |
56 ms |
11332 KB |
Output is correct |
42 |
Correct |
64 ms |
11040 KB |
Output is correct |
43 |
Correct |
59 ms |
11328 KB |
Output is correct |
44 |
Correct |
71 ms |
11356 KB |
Output is correct |
45 |
Correct |
68 ms |
11332 KB |
Output is correct |
46 |
Correct |
62 ms |
11348 KB |
Output is correct |
47 |
Correct |
33 ms |
8656 KB |
Output is correct |
48 |
Correct |
385 ms |
17708 KB |
Output is correct |
49 |
Correct |
392 ms |
17592 KB |
Output is correct |
50 |
Correct |
405 ms |
17592 KB |
Output is correct |
51 |
Correct |
389 ms |
17600 KB |
Output is correct |
52 |
Correct |
371 ms |
17388 KB |
Output is correct |
53 |
Correct |
267 ms |
17072 KB |
Output is correct |
54 |
Correct |
368 ms |
18516 KB |
Output is correct |
55 |
Correct |
409 ms |
17600 KB |
Output is correct |
56 |
Correct |
206 ms |
17696 KB |
Output is correct |
57 |
Correct |
310 ms |
18532 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
7244 KB |
Output is correct |
2 |
Correct |
6 ms |
7244 KB |
Output is correct |
3 |
Correct |
6 ms |
7244 KB |
Output is correct |
4 |
Correct |
6 ms |
7244 KB |
Output is correct |
5 |
Correct |
6 ms |
7372 KB |
Output is correct |
6 |
Correct |
6 ms |
7372 KB |
Output is correct |
7 |
Correct |
6 ms |
7372 KB |
Output is correct |
8 |
Correct |
6 ms |
7372 KB |
Output is correct |
9 |
Correct |
6 ms |
7372 KB |
Output is correct |
10 |
Correct |
45 ms |
10848 KB |
Output is correct |
11 |
Correct |
60 ms |
11168 KB |
Output is correct |
12 |
Correct |
56 ms |
11160 KB |
Output is correct |
13 |
Correct |
66 ms |
11352 KB |
Output is correct |
14 |
Correct |
58 ms |
11340 KB |
Output is correct |
15 |
Correct |
70 ms |
10948 KB |
Output is correct |
16 |
Correct |
364 ms |
12856 KB |
Output is correct |
17 |
Correct |
401 ms |
12772 KB |
Output is correct |
18 |
Correct |
366 ms |
12880 KB |
Output is correct |
19 |
Correct |
188 ms |
12916 KB |
Output is correct |
20 |
Correct |
215 ms |
13624 KB |
Output is correct |
21 |
Correct |
212 ms |
13780 KB |
Output is correct |
22 |
Correct |
218 ms |
14024 KB |
Output is correct |
23 |
Correct |
200 ms |
13604 KB |
Output is correct |
24 |
Correct |
223 ms |
13888 KB |
Output is correct |
25 |
Correct |
194 ms |
13752 KB |
Output is correct |
26 |
Correct |
183 ms |
13692 KB |
Output is correct |
27 |
Correct |
206 ms |
13752 KB |
Output is correct |
28 |
Correct |
6 ms |
7348 KB |
Output is correct |
29 |
Correct |
6 ms |
7372 KB |
Output is correct |
30 |
Correct |
7 ms |
7372 KB |
Output is correct |
31 |
Correct |
6 ms |
7372 KB |
Output is correct |
32 |
Correct |
6 ms |
7372 KB |
Output is correct |
33 |
Correct |
6 ms |
7372 KB |
Output is correct |
34 |
Correct |
6 ms |
7284 KB |
Output is correct |
35 |
Correct |
6 ms |
7372 KB |
Output is correct |
36 |
Correct |
6 ms |
7348 KB |
Output is correct |
37 |
Correct |
13 ms |
7948 KB |
Output is correct |
38 |
Correct |
68 ms |
11344 KB |
Output is correct |
39 |
Correct |
81 ms |
11328 KB |
Output is correct |
40 |
Correct |
88 ms |
11348 KB |
Output is correct |
41 |
Correct |
65 ms |
11344 KB |
Output is correct |
42 |
Correct |
56 ms |
11332 KB |
Output is correct |
43 |
Correct |
64 ms |
11040 KB |
Output is correct |
44 |
Correct |
59 ms |
11328 KB |
Output is correct |
45 |
Correct |
71 ms |
11356 KB |
Output is correct |
46 |
Correct |
68 ms |
11332 KB |
Output is correct |
47 |
Correct |
62 ms |
11348 KB |
Output is correct |
48 |
Correct |
33 ms |
8656 KB |
Output is correct |
49 |
Correct |
385 ms |
17708 KB |
Output is correct |
50 |
Correct |
392 ms |
17592 KB |
Output is correct |
51 |
Correct |
405 ms |
17592 KB |
Output is correct |
52 |
Correct |
389 ms |
17600 KB |
Output is correct |
53 |
Correct |
371 ms |
17388 KB |
Output is correct |
54 |
Correct |
267 ms |
17072 KB |
Output is correct |
55 |
Correct |
368 ms |
18516 KB |
Output is correct |
56 |
Correct |
409 ms |
17600 KB |
Output is correct |
57 |
Correct |
206 ms |
17696 KB |
Output is correct |
58 |
Correct |
310 ms |
18532 KB |
Output is correct |
59 |
Correct |
185 ms |
13428 KB |
Output is correct |
60 |
Correct |
376 ms |
17824 KB |
Output is correct |
61 |
Correct |
389 ms |
18236 KB |
Output is correct |
62 |
Correct |
366 ms |
18528 KB |
Output is correct |
63 |
Correct |
197 ms |
18580 KB |
Output is correct |
64 |
Correct |
10 ms |
7388 KB |
Output is correct |
65 |
Correct |
8 ms |
7320 KB |
Output is correct |
66 |
Correct |
7 ms |
7408 KB |
Output is correct |
67 |
Correct |
10 ms |
7372 KB |
Output is correct |
68 |
Correct |
9 ms |
7372 KB |
Output is correct |
69 |
Correct |
7 ms |
7372 KB |
Output is correct |
70 |
Correct |
9 ms |
7368 KB |
Output is correct |
71 |
Correct |
8 ms |
7372 KB |
Output is correct |
72 |
Correct |
8 ms |
7320 KB |
Output is correct |
73 |
Correct |
7 ms |
7372 KB |
Output is correct |
74 |
Correct |
89 ms |
13948 KB |
Output is correct |
75 |
Correct |
63 ms |
13120 KB |
Output is correct |
76 |
Correct |
88 ms |
13112 KB |
Output is correct |
77 |
Correct |
63 ms |
13628 KB |
Output is correct |
78 |
Correct |
71 ms |
17000 KB |
Output is correct |
79 |
Correct |
56 ms |
14140 KB |
Output is correct |
80 |
Correct |
68 ms |
14732 KB |
Output is correct |
81 |
Correct |
151 ms |
17680 KB |
Output is correct |
82 |
Correct |
111 ms |
18516 KB |
Output is correct |
83 |
Correct |
128 ms |
19136 KB |
Output is correct |
84 |
Correct |
61 ms |
13128 KB |
Output is correct |
85 |
Correct |
122 ms |
18180 KB |
Output is correct |
86 |
Correct |
73 ms |
11372 KB |
Output is correct |
87 |
Correct |
364 ms |
17600 KB |
Output is correct |
88 |
Correct |
370 ms |
17692 KB |
Output is correct |
89 |
Correct |
268 ms |
17956 KB |
Output is correct |
90 |
Correct |
255 ms |
20744 KB |
Output is correct |
91 |
Correct |
238 ms |
20468 KB |
Output is correct |
92 |
Correct |
284 ms |
19616 KB |
Output is correct |
93 |
Correct |
445 ms |
21508 KB |
Output is correct |
94 |
Correct |
337 ms |
22232 KB |
Output is correct |
95 |
Correct |
450 ms |
23020 KB |
Output is correct |
96 |
Correct |
270 ms |
17840 KB |
Output is correct |
97 |
Correct |
289 ms |
20436 KB |
Output is correct |