답안 #837623

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
837623 2023-08-25T13:09:57 Z d4xn Stranded Far From Home (BOI22_island) C++17
100 / 100
192 ms 40360 KB
#include <bits/stdc++.h>

using namespace std;

int fnd(int u, vector<int> &p){ // performs path compression
	if(p[u] < 0) return u;
	return p[u] = fnd(p[u], p);
}

void mrg(int u, int v, vector<int> &p, vector<long long> &strength){
	u = fnd(u,p), v = fnd(v,p);
	if(u==v) return;
	if(p[u] > p[v]) swap(u,v); // performs size optimization
	p[u] += p[v];
	p[v] = u;
	strength[u] += strength[v];
}

void dfs(int u, int flag, vector<int> &canwin, vector<vector<int>> &mark){
	canwin[u] &= flag;
	for(int v : mark[u]) dfs(v, canwin[u], canwin, mark);
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	int N, M;
	cin >> N >> M;
	vector<int> s(N);
	for(int &x : s) cin >> x;
	vector<vector<int>> g(N);
	for(int i = 0, u, v; i < M; i++){
		cin >> u >> v;
		u--, v--;
		g[u].push_back(v), g[v].push_back(u);
	}
	vector<int> canwin(N,1), p(N,-1), vis(N), inserted(N), rep(N);
	vector<long long> strength(N);
	vector<vector<int>> mark(N);
	vector<pair<int,int>> order(N);
	for(int i = 0; i < N; i++){
		strength[i] = s[i];
		order[i] = {s[i],i};
	}
	sort(order.begin(), order.end());
	for(auto t : order){ // insert nodes in increasing order of weight
		int u = t.second;
		for(int v : g[u]) if(inserted[v]){
			int w = rep[fnd(v,p)]; // components representant
			if(strength[fnd(v,p)] < s[u]){ // this component cannot win
				canwin[w] = 0;
			}
			if(!vis[w]){ // build structure for marking
				mark[u].push_back(w);
				vis[w] = 1;
			}
		}
		for(int v : g[u]) if(inserted[v]) vis[rep[fnd(v,p)]] = 0;
		for(int v : g[u]) if(inserted[v]) mrg(u,v,p,strength);
		rep[fnd(u,p)] = u;
		inserted[u] = 1;
	}
	dfs(order[N-1].second,1,canwin,mark); // propagate marks
	for(int i = 0; i < N; i++) cout << canwin[i];
	cout << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 596 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 112 ms 31972 KB Output is correct
4 Correct 105 ms 38624 KB Output is correct
5 Correct 137 ms 27068 KB Output is correct
6 Correct 145 ms 27908 KB Output is correct
7 Correct 133 ms 27996 KB Output is correct
8 Correct 120 ms 39660 KB Output is correct
9 Correct 115 ms 27172 KB Output is correct
10 Correct 83 ms 26048 KB Output is correct
11 Correct 110 ms 40356 KB Output is correct
12 Correct 134 ms 30612 KB Output is correct
13 Correct 115 ms 39572 KB Output is correct
14 Correct 126 ms 38628 KB Output is correct
15 Correct 114 ms 39632 KB Output is correct
16 Correct 83 ms 39152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 161 ms 28028 KB Output is correct
3 Correct 191 ms 28228 KB Output is correct
4 Correct 123 ms 39620 KB Output is correct
5 Correct 105 ms 36568 KB Output is correct
6 Correct 158 ms 28108 KB Output is correct
7 Correct 128 ms 39684 KB Output is correct
8 Correct 122 ms 39632 KB Output is correct
9 Correct 83 ms 39216 KB Output is correct
10 Correct 106 ms 31736 KB Output is correct
11 Correct 128 ms 29916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 189 ms 28368 KB Output is correct
3 Correct 161 ms 28004 KB Output is correct
4 Correct 192 ms 28132 KB Output is correct
5 Correct 189 ms 27980 KB Output is correct
6 Correct 132 ms 27860 KB Output is correct
7 Correct 98 ms 33780 KB Output is correct
8 Correct 88 ms 39628 KB Output is correct
9 Correct 86 ms 15948 KB Output is correct
10 Correct 140 ms 27972 KB Output is correct
11 Correct 124 ms 29836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 596 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 112 ms 31972 KB Output is correct
18 Correct 105 ms 38624 KB Output is correct
19 Correct 137 ms 27068 KB Output is correct
20 Correct 145 ms 27908 KB Output is correct
21 Correct 133 ms 27996 KB Output is correct
22 Correct 120 ms 39660 KB Output is correct
23 Correct 115 ms 27172 KB Output is correct
24 Correct 83 ms 26048 KB Output is correct
25 Correct 110 ms 40356 KB Output is correct
26 Correct 134 ms 30612 KB Output is correct
27 Correct 115 ms 39572 KB Output is correct
28 Correct 126 ms 38628 KB Output is correct
29 Correct 114 ms 39632 KB Output is correct
30 Correct 83 ms 39152 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 161 ms 28028 KB Output is correct
33 Correct 191 ms 28228 KB Output is correct
34 Correct 123 ms 39620 KB Output is correct
35 Correct 105 ms 36568 KB Output is correct
36 Correct 158 ms 28108 KB Output is correct
37 Correct 128 ms 39684 KB Output is correct
38 Correct 122 ms 39632 KB Output is correct
39 Correct 83 ms 39216 KB Output is correct
40 Correct 106 ms 31736 KB Output is correct
41 Correct 128 ms 29916 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 189 ms 28368 KB Output is correct
44 Correct 161 ms 28004 KB Output is correct
45 Correct 192 ms 28132 KB Output is correct
46 Correct 189 ms 27980 KB Output is correct
47 Correct 132 ms 27860 KB Output is correct
48 Correct 98 ms 33780 KB Output is correct
49 Correct 88 ms 39628 KB Output is correct
50 Correct 86 ms 15948 KB Output is correct
51 Correct 140 ms 27972 KB Output is correct
52 Correct 124 ms 29836 KB Output is correct
53 Correct 0 ms 212 KB Output is correct
54 Correct 0 ms 212 KB Output is correct
55 Correct 1 ms 296 KB Output is correct
56 Correct 1 ms 468 KB Output is correct
57 Correct 1 ms 596 KB Output is correct
58 Correct 1 ms 468 KB Output is correct
59 Correct 1 ms 468 KB Output is correct
60 Correct 1 ms 468 KB Output is correct
61 Correct 1 ms 596 KB Output is correct
62 Correct 1 ms 468 KB Output is correct
63 Correct 1 ms 596 KB Output is correct
64 Correct 2 ms 468 KB Output is correct
65 Correct 1 ms 596 KB Output is correct
66 Correct 1 ms 596 KB Output is correct
67 Correct 131 ms 32156 KB Output is correct
68 Correct 106 ms 38704 KB Output is correct
69 Correct 125 ms 27096 KB Output is correct
70 Correct 137 ms 27948 KB Output is correct
71 Correct 132 ms 27992 KB Output is correct
72 Correct 133 ms 39656 KB Output is correct
73 Correct 106 ms 27144 KB Output is correct
74 Correct 83 ms 26024 KB Output is correct
75 Correct 130 ms 40360 KB Output is correct
76 Correct 142 ms 30788 KB Output is correct
77 Correct 102 ms 39608 KB Output is correct
78 Correct 109 ms 38668 KB Output is correct
79 Correct 106 ms 39636 KB Output is correct
80 Correct 83 ms 39172 KB Output is correct
81 Correct 190 ms 28044 KB Output is correct
82 Correct 177 ms 28180 KB Output is correct
83 Correct 128 ms 39628 KB Output is correct
84 Correct 103 ms 36536 KB Output is correct
85 Correct 170 ms 28188 KB Output is correct
86 Correct 121 ms 39604 KB Output is correct
87 Correct 135 ms 39656 KB Output is correct
88 Correct 107 ms 31752 KB Output is correct
89 Correct 120 ms 29936 KB Output is correct
90 Correct 173 ms 28396 KB Output is correct
91 Correct 162 ms 28056 KB Output is correct
92 Correct 181 ms 27972 KB Output is correct
93 Correct 149 ms 27988 KB Output is correct
94 Correct 129 ms 28048 KB Output is correct
95 Correct 99 ms 33692 KB Output is correct
96 Correct 87 ms 39656 KB Output is correct
97 Correct 101 ms 15936 KB Output is correct
98 Correct 144 ms 28012 KB Output is correct
99 Correct 119 ms 29936 KB Output is correct
100 Correct 33 ms 3020 KB Output is correct
101 Correct 176 ms 28032 KB Output is correct
102 Correct 123 ms 24936 KB Output is correct
103 Correct 183 ms 26100 KB Output is correct
104 Correct 182 ms 28480 KB Output is correct