Submission #706746

# Submission time Handle Problem Language Result Execution time Memory
706746 2023-03-07T16:04:42 Z finn__ Pipes (CEOI15_pipes) C++17
20 / 100
1164 ms 12656 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;
    }
};

constexpr size_t N = 100000;

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

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

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

    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:56:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   56 |     scanf("%zu %zu", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~
pipes.cpp:63:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   63 |         scanf("%u %u", &u, &v);
      |         ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory 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 -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 3028 KB Output is correct
2 Incorrect 5 ms 2900 KB Wrong number of edges
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 124 ms 2932 KB Output is correct
2 Incorrect 97 ms 2808 KB Wrong number of edges
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 161 ms 3608 KB Wrong number of edges
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 295 ms 4928 KB Output is correct
2 Correct 237 ms 4708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 365 ms 9640 KB Output is correct
2 Incorrect 305 ms 6708 KB Wrong number of edges
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 576 ms 10692 KB Output is correct
2 Incorrect 535 ms 8152 KB Wrong number of edges
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 743 ms 12656 KB Output is correct
2 Incorrect 688 ms 8552 KB Wrong number of edges
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 907 ms 12556 KB Output is correct
2 Incorrect 867 ms 8472 KB Wrong number of edges
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1164 ms 12160 KB Output is correct
2 Correct 1156 ms 9692 KB Output is correct