# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
702214 | 2023-02-23T10:24:57 Z | lovrot | Stranded Far From Home (BOI22_island) | C++17 | 179 ms | 24684 KB |
#include <vector> #include <cstdio> #include <algorithm> #define X first #define Y second #define pb push_back using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int N = 2e5 + 10; int n, m, to[N], U[N], sol[N]; ll S[N], SUM[N]; vector<int> g[N]; vector<pair<ll, int>> p; int Find(int u) { if(u == U[u]) return u; return U[u] = Find(U[u]); } void Union(int u, int v) { u = Find(u); v = Find(v); if(u == v) return; U[v] = u; SUM[u] += SUM[v]; if(!to[v] || S[to[v]] == S[v]) to[v] = u; } int main() { for(int i = 0; i < N; i++) U[i] = i; scanf("%d%d", &n, &m); for(int i = 1; i <= n; i++) { scanf("%lld", S + i); p.pb({S[i], i}); } sort(p.begin(), p.end()); for(int i = 0; i < m; i++) { int u, v; scanf("%d%d", &u, &v); if(S[u] < S[v] || S[u] == S[v] && u < v) swap(u, v); g[u].pb(v); } for(pair<ll, int> u : p) { SUM[u.Y] = S[u.Y]; for(int v : g[u.Y]) Union(u.Y, v); } reverse(p.begin(), p.end()); to[p[0].Y] = 0; SUM[0] = 0; sol[0] = 1; for(pair<ll, int> u : p) if(sol[to[u.Y]] && SUM[u.Y] >= S[to[u.Y]]) sol[u.Y] = true; for(int i = 1; i <= n; i++) printf("%d", sol[i]); printf("\n"); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 5716 KB | Output is correct |
2 | Correct | 3 ms | 5716 KB | Output is correct |
3 | Correct | 3 ms | 5788 KB | Output is correct |
4 | Correct | 4 ms | 5844 KB | Output is correct |
5 | Correct | 4 ms | 5920 KB | Output is correct |
6 | Correct | 4 ms | 5844 KB | Output is correct |
7 | Correct | 4 ms | 5864 KB | Output is correct |
8 | Correct | 5 ms | 5844 KB | Output is correct |
9 | Correct | 4 ms | 5844 KB | Output is correct |
10 | Correct | 5 ms | 5844 KB | Output is correct |
11 | Correct | 4 ms | 5844 KB | Output is correct |
12 | Correct | 4 ms | 5908 KB | Output is correct |
13 | Correct | 4 ms | 5916 KB | Output is correct |
14 | Correct | 5 ms | 5892 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 5780 KB | Output is correct |
2 | Correct | 3 ms | 5716 KB | Output is correct |
3 | Correct | 128 ms | 18600 KB | Output is correct |
4 | Correct | 129 ms | 20992 KB | Output is correct |
5 | Correct | 131 ms | 17776 KB | Output is correct |
6 | Correct | 158 ms | 18096 KB | Output is correct |
7 | Correct | 130 ms | 18160 KB | Output is correct |
8 | Correct | 146 ms | 20572 KB | Output is correct |
9 | Correct | 116 ms | 16928 KB | Output is correct |
10 | Correct | 93 ms | 15272 KB | Output is correct |
11 | Correct | 148 ms | 20468 KB | Output is correct |
12 | Correct | 134 ms | 19248 KB | Output is correct |
13 | Correct | 140 ms | 22280 KB | Output is correct |
14 | Correct | 153 ms | 22152 KB | Output is correct |
15 | Correct | 131 ms | 20520 KB | Output is correct |
16 | Correct | 97 ms | 20412 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 5716 KB | Output is correct |
2 | Correct | 169 ms | 18344 KB | Output is correct |
3 | Correct | 167 ms | 18468 KB | Output is correct |
4 | Correct | 160 ms | 20472 KB | Output is correct |
5 | Correct | 131 ms | 20564 KB | Output is correct |
6 | Correct | 159 ms | 18396 KB | Output is correct |
7 | Correct | 148 ms | 20536 KB | Output is correct |
8 | Correct | 149 ms | 20480 KB | Output is correct |
9 | Correct | 101 ms | 20356 KB | Output is correct |
10 | Correct | 132 ms | 18692 KB | Output is correct |
11 | Correct | 163 ms | 18336 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 5716 KB | Output is correct |
2 | Correct | 171 ms | 18160 KB | Output is correct |
3 | Correct | 162 ms | 22024 KB | Output is correct |
4 | Correct | 179 ms | 22112 KB | Output is correct |
5 | Correct | 151 ms | 22172 KB | Output is correct |
6 | Correct | 135 ms | 21540 KB | Output is correct |
7 | Correct | 112 ms | 21984 KB | Output is correct |
8 | Correct | 97 ms | 24200 KB | Output is correct |
9 | Correct | 97 ms | 15204 KB | Output is correct |
10 | Correct | 126 ms | 19860 KB | Output is correct |
11 | Correct | 146 ms | 20712 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 5716 KB | Output is correct |
2 | Correct | 3 ms | 5716 KB | Output is correct |
3 | Correct | 3 ms | 5788 KB | Output is correct |
4 | Correct | 4 ms | 5844 KB | Output is correct |
5 | Correct | 4 ms | 5920 KB | Output is correct |
6 | Correct | 4 ms | 5844 KB | Output is correct |
7 | Correct | 4 ms | 5864 KB | Output is correct |
8 | Correct | 5 ms | 5844 KB | Output is correct |
9 | Correct | 4 ms | 5844 KB | Output is correct |
10 | Correct | 5 ms | 5844 KB | Output is correct |
11 | Correct | 4 ms | 5844 KB | Output is correct |
12 | Correct | 4 ms | 5908 KB | Output is correct |
13 | Correct | 4 ms | 5916 KB | Output is correct |
14 | Correct | 5 ms | 5892 KB | Output is correct |
15 | Correct | 3 ms | 5780 KB | Output is correct |
16 | Correct | 3 ms | 5716 KB | Output is correct |
17 | Correct | 128 ms | 18600 KB | Output is correct |
18 | Correct | 129 ms | 20992 KB | Output is correct |
19 | Correct | 131 ms | 17776 KB | Output is correct |
20 | Correct | 158 ms | 18096 KB | Output is correct |
21 | Correct | 130 ms | 18160 KB | Output is correct |
22 | Correct | 146 ms | 20572 KB | Output is correct |
23 | Correct | 116 ms | 16928 KB | Output is correct |
24 | Correct | 93 ms | 15272 KB | Output is correct |
25 | Correct | 148 ms | 20468 KB | Output is correct |
26 | Correct | 134 ms | 19248 KB | Output is correct |
27 | Correct | 140 ms | 22280 KB | Output is correct |
28 | Correct | 153 ms | 22152 KB | Output is correct |
29 | Correct | 131 ms | 20520 KB | Output is correct |
30 | Correct | 97 ms | 20412 KB | Output is correct |
31 | Correct | 3 ms | 5716 KB | Output is correct |
32 | Correct | 169 ms | 18344 KB | Output is correct |
33 | Correct | 167 ms | 18468 KB | Output is correct |
34 | Correct | 160 ms | 20472 KB | Output is correct |
35 | Correct | 131 ms | 20564 KB | Output is correct |
36 | Correct | 159 ms | 18396 KB | Output is correct |
37 | Correct | 148 ms | 20536 KB | Output is correct |
38 | Correct | 149 ms | 20480 KB | Output is correct |
39 | Correct | 101 ms | 20356 KB | Output is correct |
40 | Correct | 132 ms | 18692 KB | Output is correct |
41 | Correct | 163 ms | 18336 KB | Output is correct |
42 | Correct | 3 ms | 5716 KB | Output is correct |
43 | Correct | 171 ms | 18160 KB | Output is correct |
44 | Correct | 162 ms | 22024 KB | Output is correct |
45 | Correct | 179 ms | 22112 KB | Output is correct |
46 | Correct | 151 ms | 22172 KB | Output is correct |
47 | Correct | 135 ms | 21540 KB | Output is correct |
48 | Correct | 112 ms | 21984 KB | Output is correct |
49 | Correct | 97 ms | 24200 KB | Output is correct |
50 | Correct | 97 ms | 15204 KB | Output is correct |
51 | Correct | 126 ms | 19860 KB | Output is correct |
52 | Correct | 146 ms | 20712 KB | Output is correct |
53 | Correct | 3 ms | 5788 KB | Output is correct |
54 | Correct | 3 ms | 5704 KB | Output is correct |
55 | Correct | 4 ms | 5780 KB | Output is correct |
56 | Correct | 4 ms | 5844 KB | Output is correct |
57 | Correct | 4 ms | 5920 KB | Output is correct |
58 | Correct | 4 ms | 5844 KB | Output is correct |
59 | Correct | 4 ms | 5844 KB | Output is correct |
60 | Correct | 4 ms | 5792 KB | Output is correct |
61 | Correct | 4 ms | 5924 KB | Output is correct |
62 | Correct | 5 ms | 5924 KB | Output is correct |
63 | Correct | 4 ms | 5924 KB | Output is correct |
64 | Correct | 4 ms | 5928 KB | Output is correct |
65 | Correct | 4 ms | 5920 KB | Output is correct |
66 | Correct | 4 ms | 5844 KB | Output is correct |
67 | Correct | 129 ms | 22464 KB | Output is correct |
68 | Correct | 135 ms | 23516 KB | Output is correct |
69 | Correct | 133 ms | 21528 KB | Output is correct |
70 | Correct | 137 ms | 21968 KB | Output is correct |
71 | Correct | 130 ms | 22020 KB | Output is correct |
72 | Correct | 149 ms | 24436 KB | Output is correct |
73 | Correct | 116 ms | 20760 KB | Output is correct |
74 | Correct | 96 ms | 18288 KB | Output is correct |
75 | Correct | 138 ms | 23396 KB | Output is correct |
76 | Correct | 137 ms | 22012 KB | Output is correct |
77 | Correct | 129 ms | 24684 KB | Output is correct |
78 | Correct | 133 ms | 24668 KB | Output is correct |
79 | Correct | 130 ms | 24436 KB | Output is correct |
80 | Correct | 95 ms | 23528 KB | Output is correct |
81 | Correct | 161 ms | 22268 KB | Output is correct |
82 | Correct | 163 ms | 22284 KB | Output is correct |
83 | Correct | 155 ms | 24496 KB | Output is correct |
84 | Correct | 139 ms | 23076 KB | Output is correct |
85 | Correct | 159 ms | 22344 KB | Output is correct |
86 | Correct | 156 ms | 24500 KB | Output is correct |
87 | Correct | 149 ms | 24396 KB | Output is correct |
88 | Correct | 136 ms | 21924 KB | Output is correct |
89 | Correct | 140 ms | 20724 KB | Output is correct |
90 | Correct | 168 ms | 22112 KB | Output is correct |
91 | Correct | 162 ms | 22092 KB | Output is correct |
92 | Correct | 166 ms | 22120 KB | Output is correct |
93 | Correct | 155 ms | 22188 KB | Output is correct |
94 | Correct | 160 ms | 21500 KB | Output is correct |
95 | Correct | 122 ms | 22016 KB | Output is correct |
96 | Correct | 99 ms | 24240 KB | Output is correct |
97 | Correct | 100 ms | 15168 KB | Output is correct |
98 | Correct | 123 ms | 19840 KB | Output is correct |
99 | Correct | 138 ms | 20696 KB | Output is correct |
100 | Correct | 63 ms | 9164 KB | Output is correct |
101 | Correct | 173 ms | 22204 KB | Output is correct |
102 | Correct | 143 ms | 19256 KB | Output is correct |
103 | Correct | 153 ms | 20016 KB | Output is correct |
104 | Correct | 179 ms | 21956 KB | Output is correct |