답안 #965768

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
965768 2024-04-19T07:08:09 Z willychan 자매 도시 (APIO20_swap) C++17
100 / 100
174 ms 29632 KB
#include "swap.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct edge{
	int a;
	int b;
	int w;
};
vector<edge> es;
int n;
int m;
vector<vector<int> > side;
vector<int> gtime;
vector<pair<int,int> > p;
vector<bool> cyc;
vector<int> maxd;
vector<vector<int> > ele;
vector<int> deg;
int query(int x){
	while(p[x].first!=x) x=p[x].first;
	return x;
}

void init(int N, int M,std::vector<int> U, std::vector<int> V, std::vector<int> W) {
	n = N;
	m = M;
	side.resize(n);
	gtime.resize(n,-1);
	p.resize(n);
	cyc.resize(n);
	maxd.resize(n);
	ele.resize(n);
	deg.resize(n,0);
	for(int i=0;i<M;i++){
		es.push_back({U[i],V[i],W[i]});
	}
	sort(es.begin(),es.end(),[](const edge &x,const edge &y){return x.w<y.w;});
	for(int i=0;i<n;i++){
		ele[i].push_back(i)	;
		p[i]={i,0};
	}
	for(int i=0;i<m;i++){
		int u = es[i].a;
		int v = es[i].b;
		deg[es[i].a]++;
		deg[es[i].b]++;
		u = query(u);
		v = query(v);
		if(u==v){
			cyc[u]=1;
			maxd[u] = max({maxd[u],deg[es[i].a],deg[es[i].b]});
			if(gtime[u]==-1){
				for(auto e : ele[u]) gtime[e]=es[i].w;
			}
			continue;
		}
		if(ele[u].size()<ele[v].size()) swap(u,v);
		p[v] = {u,es[i].w};
		maxd[u] = max({maxd[u],deg[es[i].a],deg[es[i].b],maxd[v]});
		cyc[u] = cyc[u]|cyc[v];
		if(maxd[u]>2 || cyc[u]){
			if(gtime[u]==-1){
				for(auto e : ele[u]) gtime[e]=es[i].w;
			}
			if(gtime[v]==-1){
				for(auto e : ele[v]) gtime[e]=es[i].w;
			}
		}
		for(auto e : ele[v]) ele[u].push_back(e);
	}
}

int getMinimumFuelCapacity(int X, int Y) {
	int mc=0;	
	int x = X;
	int y = Y;
	while(x!=y){
		if(ele[x].size()<ele[y].size()) swap(x,y);
		mc = max(mc,p[y].second);
		y = p[y].first;
	}
	if(gtime[X]==-1 || gtime[Y]==-1) return -1;
	return max({mc,gtime[X],gtime[Y]});
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 39 ms 14024 KB Output is correct
10 Correct 51 ms 16616 KB Output is correct
11 Correct 48 ms 16576 KB Output is correct
12 Correct 49 ms 17600 KB Output is correct
13 Correct 51 ms 15044 KB Output is correct
14 Correct 48 ms 14020 KB Output is correct
15 Correct 131 ms 19120 KB Output is correct
16 Correct 129 ms 18704 KB Output is correct
17 Correct 133 ms 19500 KB Output is correct
18 Correct 89 ms 16524 KB Output is correct
19 Correct 72 ms 6416 KB Output is correct
20 Correct 132 ms 24392 KB Output is correct
21 Correct 136 ms 23944 KB Output is correct
22 Correct 138 ms 25260 KB Output is correct
23 Correct 91 ms 22320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 83 ms 16748 KB Output is correct
4 Correct 94 ms 21268 KB Output is correct
5 Correct 108 ms 21400 KB Output is correct
6 Correct 82 ms 21160 KB Output is correct
7 Correct 87 ms 21400 KB Output is correct
8 Correct 89 ms 20508 KB Output is correct
9 Correct 84 ms 21060 KB Output is correct
10 Correct 92 ms 20436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 604 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 39 ms 14024 KB Output is correct
11 Correct 51 ms 16616 KB Output is correct
12 Correct 48 ms 16576 KB Output is correct
13 Correct 49 ms 17600 KB Output is correct
14 Correct 51 ms 15044 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 604 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 604 KB Output is correct
34 Correct 7 ms 2844 KB Output is correct
35 Correct 48 ms 19376 KB Output is correct
36 Correct 50 ms 19400 KB Output is correct
37 Correct 51 ms 18872 KB Output is correct
38 Correct 48 ms 18272 KB Output is correct
39 Correct 46 ms 18108 KB Output is correct
40 Correct 43 ms 16584 KB Output is correct
41 Correct 53 ms 19748 KB Output is correct
42 Correct 50 ms 19656 KB Output is correct
43 Correct 41 ms 16336 KB Output is correct
44 Correct 48 ms 18436 KB Output is correct
45 Correct 72 ms 17556 KB Output is correct
46 Correct 49 ms 19240 KB Output is correct
47 Correct 46 ms 17604 KB Output is correct
48 Correct 49 ms 17092 KB Output is correct
49 Correct 52 ms 10976 KB Output is correct
50 Correct 41 ms 7628 KB Output is correct
51 Correct 53 ms 14536 KB Output is correct
52 Correct 89 ms 23236 KB Output is correct
53 Correct 75 ms 21676 KB Output is correct
54 Correct 85 ms 24900 KB Output is correct
55 Correct 48 ms 16712 KB Output is correct
56 Correct 73 ms 21188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 39 ms 14024 KB Output is correct
10 Correct 51 ms 16616 KB Output is correct
11 Correct 48 ms 16576 KB Output is correct
12 Correct 49 ms 17600 KB Output is correct
13 Correct 51 ms 15044 KB Output is correct
14 Correct 48 ms 14020 KB Output is correct
15 Correct 131 ms 19120 KB Output is correct
16 Correct 129 ms 18704 KB Output is correct
17 Correct 133 ms 19500 KB Output is correct
18 Correct 89 ms 16524 KB Output is correct
19 Correct 83 ms 16748 KB Output is correct
20 Correct 94 ms 21268 KB Output is correct
21 Correct 108 ms 21400 KB Output is correct
22 Correct 82 ms 21160 KB Output is correct
23 Correct 87 ms 21400 KB Output is correct
24 Correct 89 ms 20508 KB Output is correct
25 Correct 84 ms 21060 KB Output is correct
26 Correct 92 ms 20436 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 604 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 1 ms 604 KB Output is correct
36 Correct 7 ms 2844 KB Output is correct
37 Correct 48 ms 19376 KB Output is correct
38 Correct 50 ms 19400 KB Output is correct
39 Correct 51 ms 18872 KB Output is correct
40 Correct 48 ms 18272 KB Output is correct
41 Correct 46 ms 18108 KB Output is correct
42 Correct 43 ms 16584 KB Output is correct
43 Correct 53 ms 19748 KB Output is correct
44 Correct 50 ms 19656 KB Output is correct
45 Correct 41 ms 16336 KB Output is correct
46 Correct 48 ms 18436 KB Output is correct
47 Correct 12 ms 3100 KB Output is correct
48 Correct 136 ms 24232 KB Output is correct
49 Correct 136 ms 23876 KB Output is correct
50 Correct 134 ms 23704 KB Output is correct
51 Correct 141 ms 23608 KB Output is correct
52 Correct 124 ms 22136 KB Output is correct
53 Correct 104 ms 18088 KB Output is correct
54 Correct 159 ms 25220 KB Output is correct
55 Correct 137 ms 24620 KB Output is correct
56 Correct 89 ms 21556 KB Output is correct
57 Correct 122 ms 23596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 39 ms 14024 KB Output is correct
11 Correct 51 ms 16616 KB Output is correct
12 Correct 48 ms 16576 KB Output is correct
13 Correct 49 ms 17600 KB Output is correct
14 Correct 51 ms 15044 KB Output is correct
15 Correct 48 ms 14020 KB Output is correct
16 Correct 131 ms 19120 KB Output is correct
17 Correct 129 ms 18704 KB Output is correct
18 Correct 133 ms 19500 KB Output is correct
19 Correct 89 ms 16524 KB Output is correct
20 Correct 83 ms 16748 KB Output is correct
21 Correct 94 ms 21268 KB Output is correct
22 Correct 108 ms 21400 KB Output is correct
23 Correct 82 ms 21160 KB Output is correct
24 Correct 87 ms 21400 KB Output is correct
25 Correct 89 ms 20508 KB Output is correct
26 Correct 84 ms 21060 KB Output is correct
27 Correct 92 ms 20436 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 604 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 1 ms 604 KB Output is correct
37 Correct 7 ms 2844 KB Output is correct
38 Correct 48 ms 19376 KB Output is correct
39 Correct 50 ms 19400 KB Output is correct
40 Correct 51 ms 18872 KB Output is correct
41 Correct 48 ms 18272 KB Output is correct
42 Correct 46 ms 18108 KB Output is correct
43 Correct 43 ms 16584 KB Output is correct
44 Correct 53 ms 19748 KB Output is correct
45 Correct 50 ms 19656 KB Output is correct
46 Correct 41 ms 16336 KB Output is correct
47 Correct 48 ms 18436 KB Output is correct
48 Correct 12 ms 3100 KB Output is correct
49 Correct 136 ms 24232 KB Output is correct
50 Correct 136 ms 23876 KB Output is correct
51 Correct 134 ms 23704 KB Output is correct
52 Correct 141 ms 23608 KB Output is correct
53 Correct 124 ms 22136 KB Output is correct
54 Correct 104 ms 18088 KB Output is correct
55 Correct 159 ms 25220 KB Output is correct
56 Correct 137 ms 24620 KB Output is correct
57 Correct 89 ms 21556 KB Output is correct
58 Correct 122 ms 23596 KB Output is correct
59 Correct 72 ms 6416 KB Output is correct
60 Correct 132 ms 24392 KB Output is correct
61 Correct 136 ms 23944 KB Output is correct
62 Correct 138 ms 25260 KB Output is correct
63 Correct 91 ms 22320 KB Output is correct
64 Correct 1 ms 348 KB Output is correct
65 Correct 1 ms 604 KB Output is correct
66 Correct 1 ms 348 KB Output is correct
67 Correct 1 ms 348 KB Output is correct
68 Correct 1 ms 348 KB Output is correct
69 Correct 1 ms 604 KB Output is correct
70 Correct 1 ms 604 KB Output is correct
71 Correct 1 ms 604 KB Output is correct
72 Correct 1 ms 348 KB Output is correct
73 Correct 1 ms 604 KB Output is correct
74 Correct 72 ms 17556 KB Output is correct
75 Correct 49 ms 19240 KB Output is correct
76 Correct 46 ms 17604 KB Output is correct
77 Correct 49 ms 17092 KB Output is correct
78 Correct 52 ms 10976 KB Output is correct
79 Correct 41 ms 7628 KB Output is correct
80 Correct 53 ms 14536 KB Output is correct
81 Correct 89 ms 23236 KB Output is correct
82 Correct 75 ms 21676 KB Output is correct
83 Correct 85 ms 24900 KB Output is correct
84 Correct 48 ms 16712 KB Output is correct
85 Correct 73 ms 21188 KB Output is correct
86 Correct 35 ms 7636 KB Output is correct
87 Correct 130 ms 23852 KB Output is correct
88 Correct 131 ms 23596 KB Output is correct
89 Correct 107 ms 21220 KB Output is correct
90 Correct 106 ms 13748 KB Output is correct
91 Correct 105 ms 14284 KB Output is correct
92 Correct 109 ms 19500 KB Output is correct
93 Correct 174 ms 27224 KB Output is correct
94 Correct 142 ms 26532 KB Output is correct
95 Correct 174 ms 29632 KB Output is correct
96 Correct 97 ms 21528 KB Output is correct
97 Correct 121 ms 25896 KB Output is correct