답안 #879921

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

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

int f(int x)
{
    int w = x;
    while (p[w] != w) w = p[w];
    while (p[x] != x) r[x] |= r[p[x]], x = std::exchange(p[x], w);
    return 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[u];
    }
    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:27:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |     scanf("%d%d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~
island.cpp:28:38: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |     for (int i = 0; i < n; ++i) scanf("%d", s+i), p[i] = i, q[i] = s[i];
      |                                 ~~~~~^~~~~~~~~~~
island.cpp:32:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |         scanf("%d%d", &u, &v);
      |         ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Incorrect 0 ms 2396 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Incorrect 68 ms 5968 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Incorrect 81 ms 5976 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Incorrect 0 ms 2396 KB Output isn't correct
3 Halted 0 ms 0 KB -