# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
601893 | 2022-07-22T11:59:34 Z | JeanBombeur | Stranded Far From Home (BOI22_island) | C++17 | 251 ms | 26920 KB |
#include <iostream> #include <cstdio> #include <vector> #include <algorithm> using namespace std; // <|°_°|> // M. Broccoli const int MAX_VILLAGE = (2e5); vector <int> Adj[MAX_VILLAGE]; long long Size[MAX_VILLAGE]; pair <int, int> Sorted[MAX_VILLAGE]; bool Vu[MAX_VILLAGE]; long long Dsu[MAX_VILLAGE]; bool Valid[MAX_VILLAGE]; int nbVillages, nbRoads; int Find(int a) { if (Dsu[a] < 0) return a; int p = Find(Dsu[a]); Valid[a] &= Valid[Dsu[a]]; return Dsu[a] = p; } void Union(int old, int big) { old = Find(old); if (old == big) return; if (- Dsu[old] < Size[big]) Valid[old] = false; Dsu[big] += Dsu[old]; Dsu[old] = big; return; } void Read() { scanf("%d %d", &nbVillages, &nbRoads); for (int i = 0; i < nbVillages; i ++) { Valid[i] = true; scanf("%lld", &Size[i]); Sorted[i] = {Size[i], i}; Dsu[i] = - Size[i]; } sort(Sorted, Sorted + nbVillages); for (int i = 0; i < nbRoads; i ++) { int a, b; scanf("%d %d", &a, &b); Adj[-- a].push_back(-- b); Adj[b].push_back(a); } return; } void Solve() { for (int i = 0; i < nbVillages; i ++) { int cur = Sorted[i].second; Vu[cur] = true; for (int dest : Adj[cur]) { if (Vu[dest]) Union(dest, cur); } } for (int i = 0; i < nbVillages; i ++) { Find(i); printf("%c", Valid[i] ? '1' : '0'); } printf("\n"); return; } int main() { Read(); Solve(); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 4948 KB | Output is correct |
2 | Correct | 4 ms | 4948 KB | Output is correct |
3 | Correct | 4 ms | 4948 KB | Output is correct |
4 | Correct | 4 ms | 5144 KB | Output is correct |
5 | Correct | 5 ms | 5076 KB | Output is correct |
6 | Correct | 5 ms | 5056 KB | Output is correct |
7 | Correct | 4 ms | 5044 KB | Output is correct |
8 | Correct | 4 ms | 5044 KB | Output is correct |
9 | Correct | 4 ms | 5076 KB | Output is correct |
10 | Correct | 7 ms | 5076 KB | Output is correct |
11 | Correct | 4 ms | 5076 KB | Output is correct |
12 | Correct | 4 ms | 5076 KB | Output is correct |
13 | Correct | 4 ms | 5204 KB | Output is correct |
14 | Correct | 4 ms | 5144 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 4948 KB | Output is correct |
2 | Correct | 3 ms | 4948 KB | Output is correct |
3 | Correct | 176 ms | 18688 KB | Output is correct |
4 | Correct | 168 ms | 20772 KB | Output is correct |
5 | Correct | 180 ms | 17644 KB | Output is correct |
6 | Correct | 166 ms | 18400 KB | Output is correct |
7 | Correct | 173 ms | 19200 KB | Output is correct |
8 | Correct | 251 ms | 19224 KB | Output is correct |
9 | Correct | 154 ms | 18872 KB | Output is correct |
10 | Correct | 139 ms | 20292 KB | Output is correct |
11 | Correct | 165 ms | 26480 KB | Output is correct |
12 | Correct | 178 ms | 18576 KB | Output is correct |
13 | Correct | 153 ms | 23976 KB | Output is correct |
14 | Correct | 158 ms | 24540 KB | Output is correct |
15 | Correct | 178 ms | 20172 KB | Output is correct |
16 | Correct | 96 ms | 18992 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 5000 KB | Output is correct |
2 | Correct | 184 ms | 19720 KB | Output is correct |
3 | Correct | 190 ms | 19108 KB | Output is correct |
4 | Correct | 177 ms | 26920 KB | Output is correct |
5 | Correct | 136 ms | 23460 KB | Output is correct |
6 | Correct | 210 ms | 19788 KB | Output is correct |
7 | Correct | 156 ms | 19764 KB | Output is correct |
8 | Correct | 167 ms | 19868 KB | Output is correct |
9 | Correct | 97 ms | 18864 KB | Output is correct |
10 | Correct | 146 ms | 21348 KB | Output is correct |
11 | Correct | 156 ms | 20384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 4948 KB | Output is correct |
2 | Correct | 202 ms | 19704 KB | Output is correct |
3 | Correct | 193 ms | 20816 KB | Output is correct |
4 | Correct | 191 ms | 18124 KB | Output is correct |
5 | Correct | 178 ms | 21032 KB | Output is correct |
6 | Correct | 160 ms | 19644 KB | Output is correct |
7 | Correct | 135 ms | 23604 KB | Output is correct |
8 | Correct | 97 ms | 22900 KB | Output is correct |
9 | Correct | 134 ms | 13852 KB | Output is correct |
10 | Correct | 211 ms | 18672 KB | Output is correct |
11 | Correct | 190 ms | 19612 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 4948 KB | Output is correct |
2 | Correct | 4 ms | 4948 KB | Output is correct |
3 | Correct | 4 ms | 4948 KB | Output is correct |
4 | Correct | 4 ms | 5144 KB | Output is correct |
5 | Correct | 5 ms | 5076 KB | Output is correct |
6 | Correct | 5 ms | 5056 KB | Output is correct |
7 | Correct | 4 ms | 5044 KB | Output is correct |
8 | Correct | 4 ms | 5044 KB | Output is correct |
9 | Correct | 4 ms | 5076 KB | Output is correct |
10 | Correct | 7 ms | 5076 KB | Output is correct |
11 | Correct | 4 ms | 5076 KB | Output is correct |
12 | Correct | 4 ms | 5076 KB | Output is correct |
13 | Correct | 4 ms | 5204 KB | Output is correct |
14 | Correct | 4 ms | 5144 KB | Output is correct |
15 | Correct | 3 ms | 4948 KB | Output is correct |
16 | Correct | 3 ms | 4948 KB | Output is correct |
17 | Correct | 176 ms | 18688 KB | Output is correct |
18 | Correct | 168 ms | 20772 KB | Output is correct |
19 | Correct | 180 ms | 17644 KB | Output is correct |
20 | Correct | 166 ms | 18400 KB | Output is correct |
21 | Correct | 173 ms | 19200 KB | Output is correct |
22 | Correct | 251 ms | 19224 KB | Output is correct |
23 | Correct | 154 ms | 18872 KB | Output is correct |
24 | Correct | 139 ms | 20292 KB | Output is correct |
25 | Correct | 165 ms | 26480 KB | Output is correct |
26 | Correct | 178 ms | 18576 KB | Output is correct |
27 | Correct | 153 ms | 23976 KB | Output is correct |
28 | Correct | 158 ms | 24540 KB | Output is correct |
29 | Correct | 178 ms | 20172 KB | Output is correct |
30 | Correct | 96 ms | 18992 KB | Output is correct |
31 | Correct | 4 ms | 5000 KB | Output is correct |
32 | Correct | 184 ms | 19720 KB | Output is correct |
33 | Correct | 190 ms | 19108 KB | Output is correct |
34 | Correct | 177 ms | 26920 KB | Output is correct |
35 | Correct | 136 ms | 23460 KB | Output is correct |
36 | Correct | 210 ms | 19788 KB | Output is correct |
37 | Correct | 156 ms | 19764 KB | Output is correct |
38 | Correct | 167 ms | 19868 KB | Output is correct |
39 | Correct | 97 ms | 18864 KB | Output is correct |
40 | Correct | 146 ms | 21348 KB | Output is correct |
41 | Correct | 156 ms | 20384 KB | Output is correct |
42 | Correct | 2 ms | 4948 KB | Output is correct |
43 | Correct | 202 ms | 19704 KB | Output is correct |
44 | Correct | 193 ms | 20816 KB | Output is correct |
45 | Correct | 191 ms | 18124 KB | Output is correct |
46 | Correct | 178 ms | 21032 KB | Output is correct |
47 | Correct | 160 ms | 19644 KB | Output is correct |
48 | Correct | 135 ms | 23604 KB | Output is correct |
49 | Correct | 97 ms | 22900 KB | Output is correct |
50 | Correct | 134 ms | 13852 KB | Output is correct |
51 | Correct | 211 ms | 18672 KB | Output is correct |
52 | Correct | 190 ms | 19612 KB | Output is correct |
53 | Correct | 3 ms | 4948 KB | Output is correct |
54 | Correct | 4 ms | 4948 KB | Output is correct |
55 | Correct | 3 ms | 4948 KB | Output is correct |
56 | Correct | 6 ms | 5080 KB | Output is correct |
57 | Correct | 6 ms | 5076 KB | Output is correct |
58 | Correct | 4 ms | 5084 KB | Output is correct |
59 | Correct | 4 ms | 5076 KB | Output is correct |
60 | Correct | 4 ms | 5020 KB | Output is correct |
61 | Correct | 5 ms | 5076 KB | Output is correct |
62 | Correct | 5 ms | 5144 KB | Output is correct |
63 | Correct | 5 ms | 5076 KB | Output is correct |
64 | Correct | 5 ms | 5148 KB | Output is correct |
65 | Correct | 6 ms | 5204 KB | Output is correct |
66 | Correct | 5 ms | 5136 KB | Output is correct |
67 | Correct | 172 ms | 20748 KB | Output is correct |
68 | Correct | 166 ms | 22040 KB | Output is correct |
69 | Correct | 136 ms | 20308 KB | Output is correct |
70 | Correct | 144 ms | 19916 KB | Output is correct |
71 | Correct | 150 ms | 18020 KB | Output is correct |
72 | Correct | 192 ms | 19580 KB | Output is correct |
73 | Correct | 140 ms | 19424 KB | Output is correct |
74 | Correct | 123 ms | 19064 KB | Output is correct |
75 | Correct | 145 ms | 25560 KB | Output is correct |
76 | Correct | 159 ms | 18400 KB | Output is correct |
77 | Correct | 140 ms | 24600 KB | Output is correct |
78 | Correct | 147 ms | 23756 KB | Output is correct |
79 | Correct | 150 ms | 18916 KB | Output is correct |
80 | Correct | 93 ms | 19848 KB | Output is correct |
81 | Correct | 182 ms | 18736 KB | Output is correct |
82 | Correct | 181 ms | 19532 KB | Output is correct |
83 | Correct | 168 ms | 22752 KB | Output is correct |
84 | Correct | 156 ms | 23132 KB | Output is correct |
85 | Correct | 178 ms | 20924 KB | Output is correct |
86 | Correct | 159 ms | 20836 KB | Output is correct |
87 | Correct | 206 ms | 20696 KB | Output is correct |
88 | Correct | 138 ms | 20624 KB | Output is correct |
89 | Correct | 147 ms | 17860 KB | Output is correct |
90 | Correct | 239 ms | 18972 KB | Output is correct |
91 | Correct | 172 ms | 20940 KB | Output is correct |
92 | Correct | 216 ms | 21012 KB | Output is correct |
93 | Correct | 185 ms | 20132 KB | Output is correct |
94 | Correct | 146 ms | 19264 KB | Output is correct |
95 | Correct | 116 ms | 22912 KB | Output is correct |
96 | Correct | 125 ms | 22460 KB | Output is correct |
97 | Correct | 110 ms | 13612 KB | Output is correct |
98 | Correct | 159 ms | 19412 KB | Output is correct |
99 | Correct | 148 ms | 20472 KB | Output is correct |
100 | Correct | 48 ms | 9164 KB | Output is correct |
101 | Correct | 181 ms | 20892 KB | Output is correct |
102 | Correct | 193 ms | 16916 KB | Output is correct |
103 | Correct | 161 ms | 14796 KB | Output is correct |
104 | Correct | 177 ms | 16776 KB | Output is correct |