답안 #706745

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
706745 2023-03-07T15:53:46 Z finn__ Pipes (CEOI15_pipes) C++17
20 / 100
1065 ms 12752 KB
#include <bits/stdc++.h>
using namespace std;

struct Dsu
{
    vector<int> p;

    Dsu(size_t n) { p = vector<int>(n, -1); }

    int repr(int u) { return p[u] < 0 ? u : (p[u] = repr(p[u])); }

    bool merge(int i, int j)
    {
        i = repr(i);
        j = repr(j);
        if (i == j)
            return 0;

        if (p[i] > p[j])
            swap(i, j);
        p[i] += p[j];
        p[j] = i;
        return 1;
    }

    bool same_set(int i, int j) { return repr(i) == repr(j); }

    int set_size(int i) { return -p[repr(i)]; }
};

constexpr size_t N = 100000;

vector<unsigned> g[N];
unsigned y[N];

pair<unsigned, unsigned> find_bridges(unsigned u, unsigned p, unsigned i)
{
    y[u] = ++i;
    unsigned lu = y[u];

    for (unsigned const &v : g[u])
    {
        if (!y[v])
        {
            unsigned lv;
            tie(i, lv) = find_bridges(v, u, i);
            lu = min(lu, lv);
        }
        else if (v != p)
            lu = min(lu, y[v]);
    }

    if (lu == y[u] && p != UINT_MAX)
        printf("%u %u\n", u + 1, p + 1);
    return make_pair(i, lu);
}

int main()
{
    size_t n, m;
    scanf("%zu %zu", &n, &m);

    Dsu d1(n), d2(n);

    while (m--)
    {
        unsigned u, v;
        scanf("%u %u", &u, &v);
        u--, v--;
        if (d1.merge(u, v) || d2.merge(u, v))
            g[u].push_back(v), g[v].push_back(u);
    }

    for (unsigned i = 0; i < n; i++)
        if (!y[i])
            find_bridges(i, UINT_MAX, 0);
}

Compilation message

pipes.cpp: In function 'int main()':
pipes.cpp:61:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   61 |     scanf("%zu %zu", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~
pipes.cpp:68:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   68 |         scanf("%u %u", &u, &v);
      |         ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Incorrect 2 ms 2644 KB Wrong number of edges
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 3156 KB Output is correct
2 Incorrect 5 ms 2900 KB Wrong number of edges
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 132 ms 3376 KB Output is correct
2 Incorrect 98 ms 3176 KB Wrong number of edges
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 173 ms 4012 KB Wrong number of edges
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 269 ms 5484 KB Output is correct
2 Correct 233 ms 5044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 339 ms 9804 KB Output is correct
2 Incorrect 307 ms 6784 KB Wrong number of edges
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 529 ms 10744 KB Output is correct
2 Incorrect 522 ms 8492 KB Wrong number of edges
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 733 ms 12700 KB Output is correct
2 Incorrect 665 ms 8600 KB Wrong number of edges
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 883 ms 12752 KB Output is correct
2 Incorrect 836 ms 8772 KB Wrong number of edges
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1065 ms 12492 KB Output is correct
2 Correct 1022 ms 10052 KB Output is correct