답안 #936971

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
936971 2024-03-03T06:57:58 Z pan 자매 도시 (APIO20_swap) C++17
100 / 100
621 ms 54464 KB
#include"swap.h"
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#include "bits_stdc++.h"
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define input(x) scanf("%lld", &x);
#define input2(x, y) scanf("%lld%lld", &x, &y);
#define input3(x, y, z) scanf("%lld%lld%lld", &x, &y, &z);
#define input4(x, y, z, a) scanf("%lld%lld%lld%lld", &x, &y, &z, &a);
#define print(x, y) printf("%lld%c", x, y);
#define show(x) cerr << #x << " is " << x << endl;
#define show2(x,y) cerr << #x << " is " << x << " " << #y << " is " << y << endl;
#define show3(x,y,z) cerr << #x << " is " << x << " " << #y << " is " << y << " " << #z << " is " << z << endl;
#define discretize(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
using namespace std;
//using namespace __gnu_pbds;
//#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
//#define ordered_multiset tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>
typedef long long ll;
typedef long double ld;
typedef pair<ld, ll> pd;
typedef pair<string, ll> psl;
typedef pair<ll, ll> pi;
typedef pair<ll, pi> pii;
// general
ll const MXN = 100005;
ll const INF = 1e13;
ll n, m;
vector<pii> edgeslist;
bool compare(pii a, pii b)
{
	return a.f<b.f;
}

// persistent UFDS with union by rank
vector<pi> par[MXN], siz[MXN], mxdeg[MXN], cntedge[MXN];
ll deg[MXN];
ll timetravel(vector<pi>& arr, ll time)
{
	ll ind = ub(arr.begin(), arr.end(), mp(time, INF))-arr.begin()-1;
	return arr[ind].s;
}

ll find(ll node, ll time)
{
	ll p = timetravel(par[node], time);
	return (p!=node)?find(p, time):p;
}

void unite(ll x, ll y, ll t)
{
	deg[x]++; deg[y]++;
	ll px = find(x,t), py = find(y, t);
	if (px==py)
	{
		mxdeg[px].pb(mp(t, max(mxdeg[px].back().s, max(deg[x], deg[y]))));
		cntedge[px].pb(mp(t, cntedge[px].back().s+1));
	}
	else
	{
		if (siz[px].back().s<siz[py].back().s) swap(px, py);
		par[py].pb(mp(t, px));
		siz[px].pb(mp(t, siz[px].back().s+siz[py].back().s));
		mxdeg[px].pb(mp(t, max(max(mxdeg[px].back().s, mxdeg[py].back().s), max(deg[x], deg[y]))));
		cntedge[px].pb(mp(t, cntedge[px].back().s+1 +cntedge[py].back().s ));
	}
}

void init(int N, int M, std::vector<int> U, std::vector<int> V, std::vector<int> W)
{
	n =N, m=M;
	for (ll i=0; i<n; ++i)
	{
		par[i].pb(mp(-1, i));
		siz[i].pb(mp(-1, 1));
		mxdeg[i].pb(mp(-1, 0));
		cntedge[i].pb(mp(-1, 0));
		deg[i] = 0;
	}
	edgeslist.resize(m);
	for (ll i=0; i<m; ++i) edgeslist[i] = mp(W[i], mp(U[i], V[i]));
	sort(edgeslist.begin(), edgeslist.end(), compare);
	ll time = -1;
	for (pii e: edgeslist) unite(e.s.f, e.s.s, ++time);
}

int getMinimumFuelCapacity(int X, int Y)
{
	ll x = X, y= Y, lo = 0, hi = m;
	while (lo!=hi)
	{
		ll mid = (lo+hi)/2;
		ll px = find(x, mid), py = find(y, mid);
		if ((px==py) && ((timetravel(mxdeg[px], mid)>2) || (timetravel(cntedge[px], mid)>timetravel(siz[px], mid)-1))) hi = mid;
		else lo = mid+1;
	}
	return (lo==m)?-1: edgeslist[lo].f;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 10332 KB Output is correct
2 Correct 4 ms 10332 KB Output is correct
3 Correct 4 ms 10440 KB Output is correct
4 Correct 4 ms 10588 KB Output is correct
5 Correct 4 ms 10584 KB Output is correct
6 Correct 4 ms 10588 KB Output is correct
7 Correct 4 ms 10544 KB Output is correct
8 Correct 4 ms 10588 KB Output is correct
9 Correct 99 ms 34184 KB Output is correct
10 Correct 132 ms 39576 KB Output is correct
11 Correct 126 ms 38992 KB Output is correct
12 Correct 146 ms 40784 KB Output is correct
13 Correct 123 ms 39200 KB Output is correct
14 Correct 132 ms 34384 KB Output is correct
15 Correct 440 ms 44256 KB Output is correct
16 Correct 406 ms 43012 KB Output is correct
17 Correct 454 ms 44832 KB Output is correct
18 Correct 346 ms 43376 KB Output is correct
19 Correct 205 ms 20404 KB Output is correct
20 Correct 507 ms 44984 KB Output is correct
21 Correct 432 ms 44096 KB Output is correct
22 Correct 484 ms 46332 KB Output is correct
23 Correct 347 ms 44664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 10332 KB Output is correct
2 Correct 4 ms 10332 KB Output is correct
3 Correct 360 ms 42628 KB Output is correct
4 Correct 326 ms 43804 KB Output is correct
5 Correct 367 ms 43184 KB Output is correct
6 Correct 316 ms 43548 KB Output is correct
7 Correct 323 ms 43540 KB Output is correct
8 Correct 330 ms 42360 KB Output is correct
9 Correct 334 ms 43200 KB Output is correct
10 Correct 332 ms 42212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 10332 KB Output is correct
2 Correct 4 ms 10332 KB Output is correct
3 Correct 4 ms 10440 KB Output is correct
4 Correct 4 ms 10588 KB Output is correct
5 Correct 4 ms 10584 KB Output is correct
6 Correct 4 ms 10588 KB Output is correct
7 Correct 4 ms 10544 KB Output is correct
8 Correct 4 ms 10588 KB Output is correct
9 Correct 4 ms 10332 KB Output is correct
10 Correct 3 ms 10588 KB Output is correct
11 Correct 3 ms 10588 KB Output is correct
12 Correct 4 ms 10704 KB Output is correct
13 Correct 4 ms 10588 KB Output is correct
14 Correct 3 ms 10588 KB Output is correct
15 Correct 3 ms 10588 KB Output is correct
16 Correct 4 ms 10588 KB Output is correct
17 Correct 3 ms 10584 KB Output is correct
18 Correct 4 ms 10588 KB Output is correct
19 Correct 4 ms 10588 KB Output is correct
20 Correct 4 ms 10584 KB Output is correct
21 Correct 3 ms 10588 KB Output is correct
22 Correct 3 ms 10588 KB Output is correct
23 Correct 4 ms 10588 KB Output is correct
24 Correct 4 ms 10844 KB Output is correct
25 Correct 4 ms 10708 KB Output is correct
26 Correct 4 ms 10840 KB Output is correct
27 Correct 4 ms 10588 KB Output is correct
28 Correct 4 ms 10632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 10332 KB Output is correct
2 Correct 3 ms 10332 KB Output is correct
3 Correct 4 ms 10332 KB Output is correct
4 Correct 4 ms 10440 KB Output is correct
5 Correct 4 ms 10588 KB Output is correct
6 Correct 4 ms 10584 KB Output is correct
7 Correct 4 ms 10588 KB Output is correct
8 Correct 4 ms 10544 KB Output is correct
9 Correct 4 ms 10588 KB Output is correct
10 Correct 99 ms 34184 KB Output is correct
11 Correct 132 ms 39576 KB Output is correct
12 Correct 126 ms 38992 KB Output is correct
13 Correct 146 ms 40784 KB Output is correct
14 Correct 123 ms 39200 KB Output is correct
15 Correct 3 ms 10588 KB Output is correct
16 Correct 3 ms 10588 KB Output is correct
17 Correct 4 ms 10704 KB Output is correct
18 Correct 4 ms 10588 KB Output is correct
19 Correct 3 ms 10588 KB Output is correct
20 Correct 3 ms 10588 KB Output is correct
21 Correct 4 ms 10588 KB Output is correct
22 Correct 3 ms 10584 KB Output is correct
23 Correct 4 ms 10588 KB Output is correct
24 Correct 4 ms 10588 KB Output is correct
25 Correct 4 ms 10584 KB Output is correct
26 Correct 3 ms 10588 KB Output is correct
27 Correct 3 ms 10588 KB Output is correct
28 Correct 4 ms 10588 KB Output is correct
29 Correct 4 ms 10844 KB Output is correct
30 Correct 4 ms 10708 KB Output is correct
31 Correct 4 ms 10840 KB Output is correct
32 Correct 4 ms 10588 KB Output is correct
33 Correct 4 ms 10632 KB Output is correct
34 Correct 13 ms 14424 KB Output is correct
35 Correct 161 ms 40808 KB Output is correct
36 Correct 138 ms 40532 KB Output is correct
37 Correct 138 ms 40276 KB Output is correct
38 Correct 131 ms 40028 KB Output is correct
39 Correct 172 ms 39784 KB Output is correct
40 Correct 158 ms 37452 KB Output is correct
41 Correct 138 ms 40784 KB Output is correct
42 Correct 164 ms 40528 KB Output is correct
43 Correct 98 ms 39868 KB Output is correct
44 Correct 130 ms 40788 KB Output is correct
45 Correct 128 ms 40628 KB Output is correct
46 Correct 156 ms 40788 KB Output is correct
47 Correct 180 ms 40348 KB Output is correct
48 Correct 125 ms 40816 KB Output is correct
49 Correct 68 ms 28592 KB Output is correct
50 Correct 61 ms 23716 KB Output is correct
51 Correct 106 ms 36272 KB Output is correct
52 Correct 189 ms 47040 KB Output is correct
53 Correct 244 ms 48472 KB Output is correct
54 Correct 222 ms 50532 KB Output is correct
55 Correct 102 ms 38800 KB Output is correct
56 Correct 173 ms 47272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 10332 KB Output is correct
2 Correct 4 ms 10332 KB Output is correct
3 Correct 4 ms 10440 KB Output is correct
4 Correct 4 ms 10588 KB Output is correct
5 Correct 4 ms 10584 KB Output is correct
6 Correct 4 ms 10588 KB Output is correct
7 Correct 4 ms 10544 KB Output is correct
8 Correct 4 ms 10588 KB Output is correct
9 Correct 99 ms 34184 KB Output is correct
10 Correct 132 ms 39576 KB Output is correct
11 Correct 126 ms 38992 KB Output is correct
12 Correct 146 ms 40784 KB Output is correct
13 Correct 123 ms 39200 KB Output is correct
14 Correct 132 ms 34384 KB Output is correct
15 Correct 440 ms 44256 KB Output is correct
16 Correct 406 ms 43012 KB Output is correct
17 Correct 454 ms 44832 KB Output is correct
18 Correct 346 ms 43376 KB Output is correct
19 Correct 360 ms 42628 KB Output is correct
20 Correct 326 ms 43804 KB Output is correct
21 Correct 367 ms 43184 KB Output is correct
22 Correct 316 ms 43548 KB Output is correct
23 Correct 323 ms 43540 KB Output is correct
24 Correct 330 ms 42360 KB Output is correct
25 Correct 334 ms 43200 KB Output is correct
26 Correct 332 ms 42212 KB Output is correct
27 Correct 3 ms 10588 KB Output is correct
28 Correct 3 ms 10588 KB Output is correct
29 Correct 4 ms 10704 KB Output is correct
30 Correct 4 ms 10588 KB Output is correct
31 Correct 3 ms 10588 KB Output is correct
32 Correct 3 ms 10588 KB Output is correct
33 Correct 4 ms 10588 KB Output is correct
34 Correct 3 ms 10584 KB Output is correct
35 Correct 4 ms 10588 KB Output is correct
36 Correct 13 ms 14424 KB Output is correct
37 Correct 161 ms 40808 KB Output is correct
38 Correct 138 ms 40532 KB Output is correct
39 Correct 138 ms 40276 KB Output is correct
40 Correct 131 ms 40028 KB Output is correct
41 Correct 172 ms 39784 KB Output is correct
42 Correct 158 ms 37452 KB Output is correct
43 Correct 138 ms 40784 KB Output is correct
44 Correct 164 ms 40528 KB Output is correct
45 Correct 98 ms 39868 KB Output is correct
46 Correct 130 ms 40788 KB Output is correct
47 Correct 33 ms 14680 KB Output is correct
48 Correct 419 ms 45400 KB Output is correct
49 Correct 425 ms 45288 KB Output is correct
50 Correct 416 ms 45240 KB Output is correct
51 Correct 460 ms 45148 KB Output is correct
52 Correct 436 ms 43624 KB Output is correct
53 Correct 380 ms 36428 KB Output is correct
54 Correct 435 ms 46112 KB Output is correct
55 Correct 452 ms 45244 KB Output is correct
56 Correct 315 ms 43900 KB Output is correct
57 Correct 438 ms 46208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 10332 KB Output is correct
2 Correct 3 ms 10332 KB Output is correct
3 Correct 4 ms 10332 KB Output is correct
4 Correct 4 ms 10440 KB Output is correct
5 Correct 4 ms 10588 KB Output is correct
6 Correct 4 ms 10584 KB Output is correct
7 Correct 4 ms 10588 KB Output is correct
8 Correct 4 ms 10544 KB Output is correct
9 Correct 4 ms 10588 KB Output is correct
10 Correct 99 ms 34184 KB Output is correct
11 Correct 132 ms 39576 KB Output is correct
12 Correct 126 ms 38992 KB Output is correct
13 Correct 146 ms 40784 KB Output is correct
14 Correct 123 ms 39200 KB Output is correct
15 Correct 132 ms 34384 KB Output is correct
16 Correct 440 ms 44256 KB Output is correct
17 Correct 406 ms 43012 KB Output is correct
18 Correct 454 ms 44832 KB Output is correct
19 Correct 346 ms 43376 KB Output is correct
20 Correct 360 ms 42628 KB Output is correct
21 Correct 326 ms 43804 KB Output is correct
22 Correct 367 ms 43184 KB Output is correct
23 Correct 316 ms 43548 KB Output is correct
24 Correct 323 ms 43540 KB Output is correct
25 Correct 330 ms 42360 KB Output is correct
26 Correct 334 ms 43200 KB Output is correct
27 Correct 332 ms 42212 KB Output is correct
28 Correct 3 ms 10588 KB Output is correct
29 Correct 3 ms 10588 KB Output is correct
30 Correct 4 ms 10704 KB Output is correct
31 Correct 4 ms 10588 KB Output is correct
32 Correct 3 ms 10588 KB Output is correct
33 Correct 3 ms 10588 KB Output is correct
34 Correct 4 ms 10588 KB Output is correct
35 Correct 3 ms 10584 KB Output is correct
36 Correct 4 ms 10588 KB Output is correct
37 Correct 13 ms 14424 KB Output is correct
38 Correct 161 ms 40808 KB Output is correct
39 Correct 138 ms 40532 KB Output is correct
40 Correct 138 ms 40276 KB Output is correct
41 Correct 131 ms 40028 KB Output is correct
42 Correct 172 ms 39784 KB Output is correct
43 Correct 158 ms 37452 KB Output is correct
44 Correct 138 ms 40784 KB Output is correct
45 Correct 164 ms 40528 KB Output is correct
46 Correct 98 ms 39868 KB Output is correct
47 Correct 130 ms 40788 KB Output is correct
48 Correct 33 ms 14680 KB Output is correct
49 Correct 419 ms 45400 KB Output is correct
50 Correct 425 ms 45288 KB Output is correct
51 Correct 416 ms 45240 KB Output is correct
52 Correct 460 ms 45148 KB Output is correct
53 Correct 436 ms 43624 KB Output is correct
54 Correct 380 ms 36428 KB Output is correct
55 Correct 435 ms 46112 KB Output is correct
56 Correct 452 ms 45244 KB Output is correct
57 Correct 315 ms 43900 KB Output is correct
58 Correct 438 ms 46208 KB Output is correct
59 Correct 205 ms 20404 KB Output is correct
60 Correct 507 ms 44984 KB Output is correct
61 Correct 432 ms 44096 KB Output is correct
62 Correct 484 ms 46332 KB Output is correct
63 Correct 347 ms 44664 KB Output is correct
64 Correct 4 ms 10588 KB Output is correct
65 Correct 4 ms 10584 KB Output is correct
66 Correct 3 ms 10588 KB Output is correct
67 Correct 3 ms 10588 KB Output is correct
68 Correct 4 ms 10588 KB Output is correct
69 Correct 4 ms 10844 KB Output is correct
70 Correct 4 ms 10708 KB Output is correct
71 Correct 4 ms 10840 KB Output is correct
72 Correct 4 ms 10588 KB Output is correct
73 Correct 4 ms 10632 KB Output is correct
74 Correct 128 ms 40628 KB Output is correct
75 Correct 156 ms 40788 KB Output is correct
76 Correct 180 ms 40348 KB Output is correct
77 Correct 125 ms 40816 KB Output is correct
78 Correct 68 ms 28592 KB Output is correct
79 Correct 61 ms 23716 KB Output is correct
80 Correct 106 ms 36272 KB Output is correct
81 Correct 189 ms 47040 KB Output is correct
82 Correct 244 ms 48472 KB Output is correct
83 Correct 222 ms 50532 KB Output is correct
84 Correct 102 ms 38800 KB Output is correct
85 Correct 173 ms 47272 KB Output is correct
86 Correct 123 ms 22560 KB Output is correct
87 Correct 424 ms 45500 KB Output is correct
88 Correct 469 ms 45288 KB Output is correct
89 Correct 465 ms 43760 KB Output is correct
90 Correct 348 ms 32868 KB Output is correct
91 Correct 371 ms 36604 KB Output is correct
92 Correct 460 ms 40452 KB Output is correct
93 Correct 621 ms 51484 KB Output is correct
94 Correct 569 ms 53144 KB Output is correct
95 Correct 587 ms 54464 KB Output is correct
96 Correct 326 ms 44052 KB Output is correct
97 Correct 574 ms 48924 KB Output is correct