답안 #706734

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
706734 2023-03-07T15:34:52 Z finn__ Pipes (CEOI15_pipes) C++17
10 / 100
1259 ms 17792 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];
bitset<N> visited;

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

    for (unsigned const &v : g[u])
    {
        if (!visited[v])
        {
            unsigned lv;
            tie(i, lv) = find_bridges(v, u, i);
            l = min(l, lv);
            if (lv > y[u])
                printf("%u %u\n", u + 1, v + 1);
        }
        else if (v != p)
            l = min(l, y[v]);
    }

    return make_pair(i, l);
}

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.same_set(u, v))
            d1.merge(u, v), g[u].push_back(v), g[v].push_back(u);
        else if (!d2.same_set(u, v))
            d2.merge(u, v), g[u].push_back(v), g[v].push_back(u);
    }

    find_bridges(0, UINT_MAX, 0);
}

Compilation message

pipes.cpp: In function 'int main()':
pipes.cpp:62:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |     scanf("%zu %zu", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~
pipes.cpp:69:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   69 |         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 Incorrect 5 ms 3028 KB Wrong number of edges
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 112 ms 2944 KB Output is correct
2 Incorrect 110 ms 2904 KB Wrong number of edges
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 245 ms 3616 KB Wrong number of edges
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 305 ms 5196 KB Output is correct
2 Correct 276 ms 4840 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 402 ms 10248 KB Output is correct
2 Incorrect 362 ms 6784 KB Wrong number of edges
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 618 ms 11408 KB Output is correct
2 Incorrect 644 ms 8596 KB Wrong number of edges
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 887 ms 13588 KB Output is correct
2 Incorrect 799 ms 8680 KB Wrong number of edges
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1065 ms 13584 KB Output is correct
2 Incorrect 993 ms 8720 KB Wrong number of edges
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1259 ms 12940 KB Output is correct
2 Runtime error 1259 ms 17792 KB Memory limit exceeded
3 Halted 0 ms 0 KB -