답안 #744957

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
744957 2023-05-19T08:58:18 Z josanneo22 Stranded Far From Home (BOI22_island) C++17
100 / 100
289 ms 49744 KB
#include <bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>
#include<algorithm>
using namespace std;

#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second 
#define int long long

const int maxn = 2e5 + 500;
vector<vector<int>> adj(maxn),mrk(maxn);
vector<int> par, sz, s(maxn), inserted(maxn), power(maxn),vis(maxn), win(maxn,1), rep(maxn);
void init(int n) {
	par.resize(n); sz.resize(n);
	for (int i = 0; i < n; i++) {
		par[i] = i;
		sz[i] = 1;
	}
}
int find(int x) {
	if (par[x] == x) return x;
	else return par[x] = find(par[x]);
}
void unite(int x, int y) {
	x = find(x);
	y = find(y);
	if (x == y) return;
	if (sz[x] < sz[y]) swap(x, y);
	par[y] = x;
	sz[x] += sz[y];
	power[x] += power[y];
}
bool same(int x, int y) {
	x = find(x);
	y = find(y);
	if (x == y) return true;
	else return false;
}
//remember to init(n+5) and total_groups=n
void dfs(int u,int flag) {
	win[u] &= flag;
	for (auto& v : mrk[u]) dfs(v, win[u]);
}
signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n, m; cin >> n >> m;
	for (int i = 0; i < n; i++) {
		cin >> s[i]; power[i] = s[i];
	}
	for (int i = 0; i < m; i++) {
		int u, v; cin >> u >> v;
		u--; v--;
		adj[u].pb(v); adj[v].pb(u);
	}
	init(n + 5);
	vector<pii> ord;
	for (int i = 0; i < n; i++) ord.push_back(mp(s[i], i)); 
	sort(ord.begin(), ord.end()); 
	//note that rep[find(v)] is important:
	//due to path compression: leader is the one with largest size not max 
	//need to reset leader to u
	for (auto &t : ord) {
		int u = t.second;
		for (int v : adj[u]) if (inserted[v]) {
			int w = rep[find(v)];
			if (power[find(v)] < s[u]) {
				win[w] = 0;
			}
			if (!vis[w]) { 
				mrk[u].push_back(w);
				vis[w] = 1;
			}
		}
		for (int v : adj[u]) if (inserted[v]) vis[rep[find(v)]] = 0;
		for (int v : adj[u]) if (inserted[v]) unite(u, v);
		rep[find(u)] = u;
		inserted[u] = 1;
	}
	dfs(ord[n-1].second,1);
	for (int i = 0; i < n; i++) cout << win[i];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 19156 KB Output is correct
2 Correct 10 ms 19156 KB Output is correct
3 Correct 10 ms 19160 KB Output is correct
4 Correct 11 ms 19268 KB Output is correct
5 Correct 13 ms 19284 KB Output is correct
6 Correct 13 ms 19284 KB Output is correct
7 Correct 12 ms 19284 KB Output is correct
8 Correct 11 ms 19284 KB Output is correct
9 Correct 11 ms 19412 KB Output is correct
10 Correct 12 ms 19284 KB Output is correct
11 Correct 11 ms 19328 KB Output is correct
12 Correct 10 ms 19284 KB Output is correct
13 Correct 10 ms 19416 KB Output is correct
14 Correct 10 ms 19288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 19156 KB Output is correct
2 Correct 10 ms 19156 KB Output is correct
3 Correct 181 ms 39584 KB Output is correct
4 Correct 161 ms 47688 KB Output is correct
5 Correct 224 ms 40628 KB Output is correct
6 Correct 225 ms 41400 KB Output is correct
7 Correct 227 ms 41356 KB Output is correct
8 Correct 195 ms 49744 KB Output is correct
9 Correct 169 ms 40912 KB Output is correct
10 Correct 151 ms 40652 KB Output is correct
11 Correct 150 ms 49392 KB Output is correct
12 Correct 225 ms 42172 KB Output is correct
13 Correct 167 ms 47316 KB Output is correct
14 Correct 161 ms 46760 KB Output is correct
15 Correct 163 ms 48828 KB Output is correct
16 Correct 110 ms 47812 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 19156 KB Output is correct
2 Correct 246 ms 35880 KB Output is correct
3 Correct 253 ms 40660 KB Output is correct
4 Correct 179 ms 48816 KB Output is correct
5 Correct 148 ms 45324 KB Output is correct
6 Correct 251 ms 40724 KB Output is correct
7 Correct 173 ms 48840 KB Output is correct
8 Correct 173 ms 48776 KB Output is correct
9 Correct 114 ms 47836 KB Output is correct
10 Correct 155 ms 41912 KB Output is correct
11 Correct 179 ms 40196 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 19076 KB Output is correct
2 Correct 270 ms 37464 KB Output is correct
3 Correct 279 ms 41540 KB Output is correct
4 Correct 269 ms 41524 KB Output is correct
5 Correct 252 ms 41588 KB Output is correct
6 Correct 210 ms 41392 KB Output is correct
7 Correct 143 ms 45368 KB Output is correct
8 Correct 113 ms 49220 KB Output is correct
9 Correct 137 ms 33468 KB Output is correct
10 Correct 214 ms 39944 KB Output is correct
11 Correct 168 ms 40160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 19156 KB Output is correct
2 Correct 10 ms 19156 KB Output is correct
3 Correct 10 ms 19160 KB Output is correct
4 Correct 11 ms 19268 KB Output is correct
5 Correct 13 ms 19284 KB Output is correct
6 Correct 13 ms 19284 KB Output is correct
7 Correct 12 ms 19284 KB Output is correct
8 Correct 11 ms 19284 KB Output is correct
9 Correct 11 ms 19412 KB Output is correct
10 Correct 12 ms 19284 KB Output is correct
11 Correct 11 ms 19328 KB Output is correct
12 Correct 10 ms 19284 KB Output is correct
13 Correct 10 ms 19416 KB Output is correct
14 Correct 10 ms 19288 KB Output is correct
15 Correct 12 ms 19156 KB Output is correct
16 Correct 10 ms 19156 KB Output is correct
17 Correct 181 ms 39584 KB Output is correct
18 Correct 161 ms 47688 KB Output is correct
19 Correct 224 ms 40628 KB Output is correct
20 Correct 225 ms 41400 KB Output is correct
21 Correct 227 ms 41356 KB Output is correct
22 Correct 195 ms 49744 KB Output is correct
23 Correct 169 ms 40912 KB Output is correct
24 Correct 151 ms 40652 KB Output is correct
25 Correct 150 ms 49392 KB Output is correct
26 Correct 225 ms 42172 KB Output is correct
27 Correct 167 ms 47316 KB Output is correct
28 Correct 161 ms 46760 KB Output is correct
29 Correct 163 ms 48828 KB Output is correct
30 Correct 110 ms 47812 KB Output is correct
31 Correct 9 ms 19156 KB Output is correct
32 Correct 246 ms 35880 KB Output is correct
33 Correct 253 ms 40660 KB Output is correct
34 Correct 179 ms 48816 KB Output is correct
35 Correct 148 ms 45324 KB Output is correct
36 Correct 251 ms 40724 KB Output is correct
37 Correct 173 ms 48840 KB Output is correct
38 Correct 173 ms 48776 KB Output is correct
39 Correct 114 ms 47836 KB Output is correct
40 Correct 155 ms 41912 KB Output is correct
41 Correct 179 ms 40196 KB Output is correct
42 Correct 10 ms 19076 KB Output is correct
43 Correct 270 ms 37464 KB Output is correct
44 Correct 279 ms 41540 KB Output is correct
45 Correct 269 ms 41524 KB Output is correct
46 Correct 252 ms 41588 KB Output is correct
47 Correct 210 ms 41392 KB Output is correct
48 Correct 143 ms 45368 KB Output is correct
49 Correct 113 ms 49220 KB Output is correct
50 Correct 137 ms 33468 KB Output is correct
51 Correct 214 ms 39944 KB Output is correct
52 Correct 168 ms 40160 KB Output is correct
53 Correct 10 ms 19156 KB Output is correct
54 Correct 9 ms 19156 KB Output is correct
55 Correct 8 ms 19156 KB Output is correct
56 Correct 12 ms 19284 KB Output is correct
57 Correct 11 ms 19316 KB Output is correct
58 Correct 10 ms 19332 KB Output is correct
59 Correct 11 ms 19288 KB Output is correct
60 Correct 10 ms 19316 KB Output is correct
61 Correct 11 ms 19348 KB Output is correct
62 Correct 10 ms 19284 KB Output is correct
63 Correct 12 ms 19316 KB Output is correct
64 Correct 11 ms 19284 KB Output is correct
65 Correct 12 ms 19440 KB Output is correct
66 Correct 11 ms 19320 KB Output is correct
67 Correct 166 ms 44196 KB Output is correct
68 Correct 158 ms 47672 KB Output is correct
69 Correct 200 ms 40620 KB Output is correct
70 Correct 234 ms 41420 KB Output is correct
71 Correct 223 ms 41396 KB Output is correct
72 Correct 190 ms 49736 KB Output is correct
73 Correct 170 ms 40880 KB Output is correct
74 Correct 147 ms 40616 KB Output is correct
75 Correct 142 ms 49396 KB Output is correct
76 Correct 221 ms 42260 KB Output is correct
77 Correct 146 ms 47388 KB Output is correct
78 Correct 155 ms 46772 KB Output is correct
79 Correct 156 ms 48780 KB Output is correct
80 Correct 108 ms 47904 KB Output is correct
81 Correct 251 ms 40372 KB Output is correct
82 Correct 243 ms 40488 KB Output is correct
83 Correct 201 ms 48812 KB Output is correct
84 Correct 167 ms 45248 KB Output is correct
85 Correct 242 ms 40480 KB Output is correct
86 Correct 170 ms 48820 KB Output is correct
87 Correct 171 ms 48820 KB Output is correct
88 Correct 159 ms 41876 KB Output is correct
89 Correct 169 ms 40244 KB Output is correct
90 Correct 269 ms 41692 KB Output is correct
91 Correct 260 ms 41372 KB Output is correct
92 Correct 283 ms 41608 KB Output is correct
93 Correct 242 ms 41564 KB Output is correct
94 Correct 210 ms 41476 KB Output is correct
95 Correct 148 ms 45460 KB Output is correct
96 Correct 111 ms 49216 KB Output is correct
97 Correct 135 ms 33340 KB Output is correct
98 Correct 225 ms 39948 KB Output is correct
99 Correct 171 ms 40176 KB Output is correct
100 Correct 55 ms 25756 KB Output is correct
101 Correct 289 ms 41548 KB Output is correct
102 Correct 191 ms 39780 KB Output is correct
103 Correct 252 ms 40504 KB Output is correct
104 Correct 288 ms 41776 KB Output is correct