Submission #984300

# Submission time Handle Problem Language Result Execution time Memory
984300 2024-05-16T12:54:21 Z OAleksa Stranded Far From Home (BOI22_island) C++14
100 / 100
198 ms 52652 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; 
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 16984 KB Output is correct
2 Correct 3 ms 17004 KB Output is correct
3 Correct 3 ms 16988 KB Output is correct
4 Correct 4 ms 17244 KB Output is correct
5 Correct 4 ms 17244 KB Output is correct
6 Correct 4 ms 17240 KB Output is correct
7 Correct 4 ms 17240 KB Output is correct
8 Correct 5 ms 17492 KB Output is correct
9 Correct 4 ms 17244 KB Output is correct
10 Correct 4 ms 17320 KB Output is correct
11 Correct 5 ms 17244 KB Output is correct
12 Correct 5 ms 17244 KB Output is correct
13 Correct 5 ms 17240 KB Output is correct
14 Correct 4 ms 17244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 16984 KB Output is correct
2 Correct 3 ms 16988 KB Output is correct
3 Correct 148 ms 41436 KB Output is correct
4 Correct 119 ms 42188 KB Output is correct
5 Correct 137 ms 48116 KB Output is correct
6 Correct 159 ms 49420 KB Output is correct
7 Correct 152 ms 49144 KB Output is correct
8 Correct 146 ms 46052 KB Output is correct
9 Correct 137 ms 50680 KB Output is correct
10 Correct 100 ms 39948 KB Output is correct
11 Correct 113 ms 47196 KB Output is correct
12 Correct 133 ms 40872 KB Output is correct
13 Correct 119 ms 40924 KB Output is correct
14 Correct 120 ms 41204 KB Output is correct
15 Correct 118 ms 45736 KB Output is correct
16 Correct 83 ms 44020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 16988 KB Output is correct
2 Correct 147 ms 44664 KB Output is correct
3 Correct 157 ms 49424 KB Output is correct
4 Correct 130 ms 44632 KB Output is correct
5 Correct 118 ms 43376 KB Output is correct
6 Correct 152 ms 49400 KB Output is correct
7 Correct 131 ms 45812 KB Output is correct
8 Correct 127 ms 44536 KB Output is correct
9 Correct 84 ms 44532 KB Output is correct
10 Correct 126 ms 43508 KB Output is correct
11 Correct 130 ms 40692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 16988 KB Output is correct
2 Correct 168 ms 41704 KB Output is correct
3 Correct 157 ms 47604 KB Output is correct
4 Correct 180 ms 49136 KB Output is correct
5 Correct 179 ms 52652 KB Output is correct
6 Correct 171 ms 47608 KB Output is correct
7 Correct 115 ms 46264 KB Output is correct
8 Correct 95 ms 44784 KB Output is correct
9 Correct 96 ms 36168 KB Output is correct
10 Correct 198 ms 49904 KB Output is correct
11 Correct 131 ms 41712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 16984 KB Output is correct
2 Correct 3 ms 17004 KB Output is correct
3 Correct 3 ms 16988 KB Output is correct
4 Correct 4 ms 17244 KB Output is correct
5 Correct 4 ms 17244 KB Output is correct
6 Correct 4 ms 17240 KB Output is correct
7 Correct 4 ms 17240 KB Output is correct
8 Correct 5 ms 17492 KB Output is correct
9 Correct 4 ms 17244 KB Output is correct
10 Correct 4 ms 17320 KB Output is correct
11 Correct 5 ms 17244 KB Output is correct
12 Correct 5 ms 17244 KB Output is correct
13 Correct 5 ms 17240 KB Output is correct
14 Correct 4 ms 17244 KB Output is correct
15 Correct 4 ms 16984 KB Output is correct
16 Correct 3 ms 16988 KB Output is correct
17 Correct 148 ms 41436 KB Output is correct
18 Correct 119 ms 42188 KB Output is correct
19 Correct 137 ms 48116 KB Output is correct
20 Correct 159 ms 49420 KB Output is correct
21 Correct 152 ms 49144 KB Output is correct
22 Correct 146 ms 46052 KB Output is correct
23 Correct 137 ms 50680 KB Output is correct
24 Correct 100 ms 39948 KB Output is correct
25 Correct 113 ms 47196 KB Output is correct
26 Correct 133 ms 40872 KB Output is correct
27 Correct 119 ms 40924 KB Output is correct
28 Correct 120 ms 41204 KB Output is correct
29 Correct 118 ms 45736 KB Output is correct
30 Correct 83 ms 44020 KB Output is correct
31 Correct 3 ms 16988 KB Output is correct
32 Correct 147 ms 44664 KB Output is correct
33 Correct 157 ms 49424 KB Output is correct
34 Correct 130 ms 44632 KB Output is correct
35 Correct 118 ms 43376 KB Output is correct
36 Correct 152 ms 49400 KB Output is correct
37 Correct 131 ms 45812 KB Output is correct
38 Correct 127 ms 44536 KB Output is correct
39 Correct 84 ms 44532 KB Output is correct
40 Correct 126 ms 43508 KB Output is correct
41 Correct 130 ms 40692 KB Output is correct
42 Correct 4 ms 16988 KB Output is correct
43 Correct 168 ms 41704 KB Output is correct
44 Correct 157 ms 47604 KB Output is correct
45 Correct 180 ms 49136 KB Output is correct
46 Correct 179 ms 52652 KB Output is correct
47 Correct 171 ms 47608 KB Output is correct
48 Correct 115 ms 46264 KB Output is correct
49 Correct 95 ms 44784 KB Output is correct
50 Correct 96 ms 36168 KB Output is correct
51 Correct 198 ms 49904 KB Output is correct
52 Correct 131 ms 41712 KB Output is correct
53 Correct 4 ms 17156 KB Output is correct
54 Correct 3 ms 16988 KB Output is correct
55 Correct 3 ms 16988 KB Output is correct
56 Correct 4 ms 17244 KB Output is correct
57 Correct 5 ms 17260 KB Output is correct
58 Correct 5 ms 17244 KB Output is correct
59 Correct 4 ms 17244 KB Output is correct
60 Correct 4 ms 17244 KB Output is correct
61 Correct 4 ms 17052 KB Output is correct
62 Correct 4 ms 17244 KB Output is correct
63 Correct 4 ms 17244 KB Output is correct
64 Correct 4 ms 17244 KB Output is correct
65 Correct 4 ms 17244 KB Output is correct
66 Correct 4 ms 17052 KB Output is correct
67 Correct 146 ms 45508 KB Output is correct
68 Correct 128 ms 41976 KB Output is correct
69 Correct 155 ms 47620 KB Output is correct
70 Correct 140 ms 48620 KB Output is correct
71 Correct 169 ms 48680 KB Output is correct
72 Correct 135 ms 46776 KB Output is correct
73 Correct 144 ms 51184 KB Output is correct
74 Correct 110 ms 39892 KB Output is correct
75 Correct 105 ms 46528 KB Output is correct
76 Correct 140 ms 41776 KB Output is correct
77 Correct 116 ms 41504 KB Output is correct
78 Correct 132 ms 41080 KB Output is correct
79 Correct 145 ms 46096 KB Output is correct
80 Correct 85 ms 44280 KB Output is correct
81 Correct 155 ms 49204 KB Output is correct
82 Correct 188 ms 49320 KB Output is correct
83 Correct 133 ms 44748 KB Output is correct
84 Correct 123 ms 43760 KB Output is correct
85 Correct 152 ms 49396 KB Output is correct
86 Correct 143 ms 45072 KB Output is correct
87 Correct 121 ms 45552 KB Output is correct
88 Correct 123 ms 42228 KB Output is correct
89 Correct 140 ms 41008 KB Output is correct
90 Correct 161 ms 45904 KB Output is correct
91 Correct 153 ms 47648 KB Output is correct
92 Correct 170 ms 49144 KB Output is correct
93 Correct 179 ms 52164 KB Output is correct
94 Correct 167 ms 47428 KB Output is correct
95 Correct 143 ms 46096 KB Output is correct
96 Correct 96 ms 45308 KB Output is correct
97 Correct 107 ms 35976 KB Output is correct
98 Correct 160 ms 49396 KB Output is correct
99 Correct 128 ms 41324 KB Output is correct
100 Correct 56 ms 29256 KB Output is correct
101 Correct 163 ms 48628 KB Output is correct
102 Correct 145 ms 46672 KB Output is correct
103 Correct 140 ms 42740 KB Output is correct
104 Correct 157 ms 44892 KB Output is correct