답안 #879930

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
879930 2023-11-28T10:31:08 Z sleepntsheep Stranded Far From Home (BOI22_island) C++17
100 / 100
89 ms 14420 KB
#include <iostream>
#include <utility>
#include <vector>
#include <tuple>
#include <algorithm>

int n, m, s[200000], p[200000], r[200000];
long long q[200000];

int f(int x)
{
    if (p[x] == x) return x;
    int w = f(p[x]);
    r[x] |= r[p[x]];
    return p[x] = w;
}

void u_(int x, int y)
{
    if ((x = f(x)) == (y = f(y))) return;
    if (q[x] < s[y]) r[x] = 1;
    q[y] += q[x];
    p[x] = y;
}

int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; ++i) scanf("%d", s+i), p[i] = i, q[i] = s[i];
    std::vector<std::tuple<int, int, int>> e(m);
    for (auto &[w, u, v] : e)
    {
        scanf("%d%d", &u, &v);
        if (s[--u] > s[--v]) std::swap(u, v);
        w = s[v];
    }
    std::sort(e.begin(), e.end());
    for (auto [_, u, v] : e) u_(u, v);
    for (int i = 0; i < n; ++i) f(i), putchar(48+!r[i]);

    return 0;
}

Compilation message

island.cpp: In function 'int main()':
island.cpp:28:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |     scanf("%d%d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~
island.cpp:29:38: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |     for (int i = 0; i < n; ++i) scanf("%d", s+i), p[i] = i, q[i] = s[i];
      |                                 ~~~~~^~~~~~~~~~~
island.cpp:33:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |         scanf("%d%d", &u, &v);
      |         ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 2 ms 2560 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 2 ms 2396 KB Output is correct
12 Correct 1 ms 2504 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 66 ms 6704 KB Output is correct
4 Correct 64 ms 11348 KB Output is correct
5 Correct 64 ms 10788 KB Output is correct
6 Correct 67 ms 11004 KB Output is correct
7 Correct 65 ms 11196 KB Output is correct
8 Correct 81 ms 11348 KB Output is correct
9 Correct 64 ms 11076 KB Output is correct
10 Correct 62 ms 10388 KB Output is correct
11 Correct 75 ms 13332 KB Output is correct
12 Correct 79 ms 9808 KB Output is correct
13 Correct 63 ms 12708 KB Output is correct
14 Correct 63 ms 12628 KB Output is correct
15 Correct 62 ms 11096 KB Output is correct
16 Correct 46 ms 10360 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 66 ms 6828 KB Output is correct
3 Correct 69 ms 11088 KB Output is correct
4 Correct 68 ms 14420 KB Output is correct
5 Correct 66 ms 11784 KB Output is correct
6 Correct 73 ms 11416 KB Output is correct
7 Correct 62 ms 11292 KB Output is correct
8 Correct 67 ms 11164 KB Output is correct
9 Correct 45 ms 10364 KB Output is correct
10 Correct 66 ms 13648 KB Output is correct
11 Correct 66 ms 10832 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 75 ms 6844 KB Output is correct
3 Correct 80 ms 11216 KB Output is correct
4 Correct 78 ms 11164 KB Output is correct
5 Correct 75 ms 11268 KB Output is correct
6 Correct 74 ms 10928 KB Output is correct
7 Correct 66 ms 13648 KB Output is correct
8 Correct 59 ms 11604 KB Output is correct
9 Correct 68 ms 8640 KB Output is correct
10 Correct 70 ms 9620 KB Output is correct
11 Correct 67 ms 10684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 2 ms 2560 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 2 ms 2396 KB Output is correct
12 Correct 1 ms 2504 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 456 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 66 ms 6704 KB Output is correct
18 Correct 64 ms 11348 KB Output is correct
19 Correct 64 ms 10788 KB Output is correct
20 Correct 67 ms 11004 KB Output is correct
21 Correct 65 ms 11196 KB Output is correct
22 Correct 81 ms 11348 KB Output is correct
23 Correct 64 ms 11076 KB Output is correct
24 Correct 62 ms 10388 KB Output is correct
25 Correct 75 ms 13332 KB Output is correct
26 Correct 79 ms 9808 KB Output is correct
27 Correct 63 ms 12708 KB Output is correct
28 Correct 63 ms 12628 KB Output is correct
29 Correct 62 ms 11096 KB Output is correct
30 Correct 46 ms 10360 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 66 ms 6828 KB Output is correct
33 Correct 69 ms 11088 KB Output is correct
34 Correct 68 ms 14420 KB Output is correct
35 Correct 66 ms 11784 KB Output is correct
36 Correct 73 ms 11416 KB Output is correct
37 Correct 62 ms 11292 KB Output is correct
38 Correct 67 ms 11164 KB Output is correct
39 Correct 45 ms 10364 KB Output is correct
40 Correct 66 ms 13648 KB Output is correct
41 Correct 66 ms 10832 KB Output is correct
42 Correct 0 ms 344 KB Output is correct
43 Correct 75 ms 6844 KB Output is correct
44 Correct 80 ms 11216 KB Output is correct
45 Correct 78 ms 11164 KB Output is correct
46 Correct 75 ms 11268 KB Output is correct
47 Correct 74 ms 10928 KB Output is correct
48 Correct 66 ms 13648 KB Output is correct
49 Correct 59 ms 11604 KB Output is correct
50 Correct 68 ms 8640 KB Output is correct
51 Correct 70 ms 9620 KB Output is correct
52 Correct 67 ms 10684 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 1 ms 2396 KB Output is correct
55 Correct 0 ms 348 KB Output is correct
56 Correct 1 ms 2548 KB Output is correct
57 Correct 1 ms 2648 KB Output is correct
58 Correct 1 ms 492 KB Output is correct
59 Correct 1 ms 2396 KB Output is correct
60 Correct 1 ms 2392 KB Output is correct
61 Correct 1 ms 344 KB Output is correct
62 Correct 1 ms 2392 KB Output is correct
63 Correct 1 ms 2568 KB Output is correct
64 Correct 1 ms 2396 KB Output is correct
65 Correct 1 ms 348 KB Output is correct
66 Correct 1 ms 348 KB Output is correct
67 Correct 66 ms 11272 KB Output is correct
68 Correct 70 ms 11440 KB Output is correct
69 Correct 64 ms 10920 KB Output is correct
70 Correct 68 ms 11176 KB Output is correct
71 Correct 65 ms 11092 KB Output is correct
72 Correct 77 ms 11160 KB Output is correct
73 Correct 65 ms 11160 KB Output is correct
74 Correct 61 ms 10400 KB Output is correct
75 Correct 63 ms 13308 KB Output is correct
76 Correct 89 ms 9904 KB Output is correct
77 Correct 68 ms 12880 KB Output is correct
78 Correct 75 ms 12728 KB Output is correct
79 Correct 63 ms 11164 KB Output is correct
80 Correct 45 ms 10480 KB Output is correct
81 Correct 67 ms 11344 KB Output is correct
82 Correct 70 ms 11148 KB Output is correct
83 Correct 68 ms 14352 KB Output is correct
84 Correct 61 ms 11684 KB Output is correct
85 Correct 69 ms 11092 KB Output is correct
86 Correct 66 ms 11348 KB Output is correct
87 Correct 68 ms 11164 KB Output is correct
88 Correct 67 ms 13652 KB Output is correct
89 Correct 65 ms 10832 KB Output is correct
90 Correct 79 ms 11344 KB Output is correct
91 Correct 76 ms 11084 KB Output is correct
92 Correct 78 ms 11164 KB Output is correct
93 Correct 74 ms 11092 KB Output is correct
94 Correct 74 ms 11028 KB Output is correct
95 Correct 70 ms 13696 KB Output is correct
96 Correct 59 ms 11600 KB Output is correct
97 Correct 63 ms 8276 KB Output is correct
98 Correct 68 ms 9556 KB Output is correct
99 Correct 69 ms 10920 KB Output is correct
100 Correct 50 ms 6784 KB Output is correct
101 Correct 83 ms 11184 KB Output is correct
102 Correct 70 ms 10204 KB Output is correct
103 Correct 77 ms 10532 KB Output is correct
104 Correct 75 ms 11088 KB Output is correct