답안 #987304

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
987304 2024-05-22T14:25:16 Z batsukh2006 Stranded Far From Home (BOI22_island) C++11
100 / 100
222 ms 52828 KB
#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
const int N = 2e5 + 69;
#define int long long
int n, m, a[N], p[N], sz[N], sum[N], vis[N], ans[N];
vector<int> g[N], can[N];
int root(int v) {
	if (p[v] == v)
		return v;
	return p[v] = root(p[v]);
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int tt = 1;
  //cin >> tt;
  while (tt--) {
  	cin >> n >> m;
  	for (int i = 1;i <= n;i++) {
  		cin >> a[i];
  		p[i] = i, sz[i] = 1;
  		sum[i] = a[i];
  		can[i].push_back(i);
  	}
  	vector<tuple<int, int, int>> edges;
  	for (int i = 1;i <= m;i++) {
  		int x, y;
  		cin >> x >> y;
  		g[x].push_back(y);
  		g[y].push_back(x);
  		int c = max(a[x], a[y]);
  		edges.push_back({c, x, y});
  	}   
  	sort(edges.begin(), edges.end());
  	for (auto u : edges) {
  		int a1, b1, c;
  		tie(c, a1, b1) = u;
  		int x = root(a1);
  		int y = root(b1);
  		assert(sum[x] >= a[a1] && sum[y] >= a[b1]);
  		if (x != y) {
  			if (sum[x] >= c && sum[y] >= c) {
  				if (sz[x] < sz[y])
  					swap(x, y);
  				for (auto j : can[y]) 
  					can[x].push_back(j);
  			}
  			else {
  				if (sum[x] < sum[y])
  					swap(x, y);
  			}
  			p[y] = x;
  			sz[x] += sz[y];
  			sum[x] += sum[y];
  		}
  	}
  	// int ok = 1;
  	// for (int i = 2;i <= n;i++)
  	// 	ok &= (root(i) == root(i - 1));
  	// assert(ok);
  	for (auto j : can[root(1)])
  		ans[j] = 1;
  	for (int i = 1;i <= n;i++)
  		cout << ans[i];
  	cout << '\n';
  }
  return 0; 
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 16984 KB Output is correct
2 Correct 5 ms 16988 KB Output is correct
3 Correct 7 ms 16984 KB Output is correct
4 Correct 5 ms 17244 KB Output is correct
5 Correct 8 ms 17320 KB Output is correct
6 Correct 6 ms 17244 KB Output is correct
7 Correct 6 ms 17244 KB Output is correct
8 Correct 6 ms 17244 KB Output is correct
9 Correct 5 ms 17240 KB Output is correct
10 Correct 6 ms 17244 KB Output is correct
11 Correct 5 ms 17244 KB Output is correct
12 Correct 5 ms 17244 KB Output is correct
13 Correct 4 ms 17244 KB Output is correct
14 Correct 5 ms 17244 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 17144 KB Output is correct
2 Correct 5 ms 16988 KB Output is correct
3 Correct 160 ms 44784 KB Output is correct
4 Correct 131 ms 42996 KB Output is correct
5 Correct 176 ms 48624 KB Output is correct
6 Correct 168 ms 49144 KB Output is correct
7 Correct 164 ms 49564 KB Output is correct
8 Correct 155 ms 46608 KB Output is correct
9 Correct 157 ms 50676 KB Output is correct
10 Correct 110 ms 39616 KB Output is correct
11 Correct 115 ms 45152 KB Output is correct
12 Correct 161 ms 41464 KB Output is correct
13 Correct 144 ms 40952 KB Output is correct
14 Correct 144 ms 42996 KB Output is correct
15 Correct 145 ms 45564 KB Output is correct
16 Correct 87 ms 43664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 16988 KB Output is correct
2 Correct 188 ms 47224 KB Output is correct
3 Correct 219 ms 50216 KB Output is correct
4 Correct 146 ms 45524 KB Output is correct
5 Correct 131 ms 43252 KB Output is correct
6 Correct 211 ms 49104 KB Output is correct
7 Correct 133 ms 45212 KB Output is correct
8 Correct 141 ms 44536 KB Output is correct
9 Correct 88 ms 44788 KB Output is correct
10 Correct 148 ms 42372 KB Output is correct
11 Correct 149 ms 41456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 16988 KB Output is correct
2 Correct 190 ms 44676 KB Output is correct
3 Correct 204 ms 47344 KB Output is correct
4 Correct 186 ms 49136 KB Output is correct
5 Correct 222 ms 52180 KB Output is correct
6 Correct 175 ms 47860 KB Output is correct
7 Correct 125 ms 46692 KB Output is correct
8 Correct 102 ms 44020 KB Output is correct
9 Correct 117 ms 36088 KB Output is correct
10 Correct 201 ms 49652 KB Output is correct
11 Correct 150 ms 41612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 16984 KB Output is correct
2 Correct 5 ms 16988 KB Output is correct
3 Correct 7 ms 16984 KB Output is correct
4 Correct 5 ms 17244 KB Output is correct
5 Correct 8 ms 17320 KB Output is correct
6 Correct 6 ms 17244 KB Output is correct
7 Correct 6 ms 17244 KB Output is correct
8 Correct 6 ms 17244 KB Output is correct
9 Correct 5 ms 17240 KB Output is correct
10 Correct 6 ms 17244 KB Output is correct
11 Correct 5 ms 17244 KB Output is correct
12 Correct 5 ms 17244 KB Output is correct
13 Correct 4 ms 17244 KB Output is correct
14 Correct 5 ms 17244 KB Output is correct
15 Correct 7 ms 17144 KB Output is correct
16 Correct 5 ms 16988 KB Output is correct
17 Correct 160 ms 44784 KB Output is correct
18 Correct 131 ms 42996 KB Output is correct
19 Correct 176 ms 48624 KB Output is correct
20 Correct 168 ms 49144 KB Output is correct
21 Correct 164 ms 49564 KB Output is correct
22 Correct 155 ms 46608 KB Output is correct
23 Correct 157 ms 50676 KB Output is correct
24 Correct 110 ms 39616 KB Output is correct
25 Correct 115 ms 45152 KB Output is correct
26 Correct 161 ms 41464 KB Output is correct
27 Correct 144 ms 40952 KB Output is correct
28 Correct 144 ms 42996 KB Output is correct
29 Correct 145 ms 45564 KB Output is correct
30 Correct 87 ms 43664 KB Output is correct
31 Correct 5 ms 16988 KB Output is correct
32 Correct 188 ms 47224 KB Output is correct
33 Correct 219 ms 50216 KB Output is correct
34 Correct 146 ms 45524 KB Output is correct
35 Correct 131 ms 43252 KB Output is correct
36 Correct 211 ms 49104 KB Output is correct
37 Correct 133 ms 45212 KB Output is correct
38 Correct 141 ms 44536 KB Output is correct
39 Correct 88 ms 44788 KB Output is correct
40 Correct 148 ms 42372 KB Output is correct
41 Correct 149 ms 41456 KB Output is correct
42 Correct 4 ms 16988 KB Output is correct
43 Correct 190 ms 44676 KB Output is correct
44 Correct 204 ms 47344 KB Output is correct
45 Correct 186 ms 49136 KB Output is correct
46 Correct 222 ms 52180 KB Output is correct
47 Correct 175 ms 47860 KB Output is correct
48 Correct 125 ms 46692 KB Output is correct
49 Correct 102 ms 44020 KB Output is correct
50 Correct 117 ms 36088 KB Output is correct
51 Correct 201 ms 49652 KB Output is correct
52 Correct 150 ms 41612 KB Output is correct
53 Correct 4 ms 16984 KB Output is correct
54 Correct 5 ms 16988 KB Output is correct
55 Correct 3 ms 16824 KB Output is correct
56 Correct 5 ms 17140 KB Output is correct
57 Correct 6 ms 17244 KB Output is correct
58 Correct 5 ms 17240 KB Output is correct
59 Correct 7 ms 17240 KB Output is correct
60 Correct 5 ms 17244 KB Output is correct
61 Correct 4 ms 17240 KB Output is correct
62 Correct 5 ms 17240 KB Output is correct
63 Correct 7 ms 17264 KB Output is correct
64 Correct 7 ms 17244 KB Output is correct
65 Correct 5 ms 17240 KB Output is correct
66 Correct 6 ms 17244 KB Output is correct
67 Correct 145 ms 45452 KB Output is correct
68 Correct 132 ms 42996 KB Output is correct
69 Correct 157 ms 47860 KB Output is correct
70 Correct 154 ms 48700 KB Output is correct
71 Correct 172 ms 50428 KB Output is correct
72 Correct 161 ms 46576 KB Output is correct
73 Correct 143 ms 50676 KB Output is correct
74 Correct 119 ms 40548 KB Output is correct
75 Correct 111 ms 46432 KB Output is correct
76 Correct 163 ms 41032 KB Output is correct
77 Correct 131 ms 40952 KB Output is correct
78 Correct 133 ms 42176 KB Output is correct
79 Correct 138 ms 44532 KB Output is correct
80 Correct 88 ms 44324 KB Output is correct
81 Correct 159 ms 49084 KB Output is correct
82 Correct 171 ms 49800 KB Output is correct
83 Correct 140 ms 46072 KB Output is correct
84 Correct 133 ms 43816 KB Output is correct
85 Correct 172 ms 49468 KB Output is correct
86 Correct 129 ms 45048 KB Output is correct
87 Correct 140 ms 44756 KB Output is correct
88 Correct 139 ms 42208 KB Output is correct
89 Correct 146 ms 40688 KB Output is correct
90 Correct 191 ms 47092 KB Output is correct
91 Correct 197 ms 47404 KB Output is correct
92 Correct 195 ms 48480 KB Output is correct
93 Correct 197 ms 52828 KB Output is correct
94 Correct 190 ms 48020 KB Output is correct
95 Correct 117 ms 46444 KB Output is correct
96 Correct 99 ms 44088 KB Output is correct
97 Correct 121 ms 35760 KB Output is correct
98 Correct 173 ms 49400 KB Output is correct
99 Correct 170 ms 41696 KB Output is correct
100 Correct 58 ms 29584 KB Output is correct
101 Correct 196 ms 47300 KB Output is correct
102 Correct 164 ms 44724 KB Output is correct
103 Correct 163 ms 42368 KB Output is correct
104 Correct 186 ms 46152 KB Output is correct