Submission #503898

# Submission time Handle Problem Language Result Execution time Memory
503898 2022-01-09T06:44:29 Z CraniXort Pipes (CEOI15_pipes) C++17
60 / 100
3291 ms 65536 KB
#include <bits/stdc++.h>
#define maxn 100005

#define fin std::cin
#define fout std::cout

// std::ifstream fin("pipes.in");
// std::ofstream fout("pipes.out");

std::vector <int> edge[maxn];
int disc[maxn], low[maxn], timer;
bool visited[maxn];

void dfs(int node, int parent) {
    visited[node] = true;
    disc[node] = low[node] = ++timer;

    bool ok = false;

    for(auto next: edge[node]) {
        if(next == parent and ok == false) {
            ok = true;
            continue;
        }
        if(visited[next] == false) {
            dfs(next, node);
            low[node] = std::min(low[node], low[next]);

            if(low[next] > disc[node]) {
                fout << node << ' ' << next << '\n';
            }
        }
        else{
            low[node] = std::min(low[node], disc[next]);
        }
    }
}

class DSU {
    int size;
    std::vector <int> rank, parent;

    public:
    DSU(int size): size(size) {
        rank.resize(size+1);
        parent.resize(size+1);

        for(int i = 1; i <= size; i ++)
            parent[i] = i;
    }

    int findRoot(int node) {
        if(parent[node] == node)
            return node;
        return (parent[node] = findRoot(parent[node]));
    }

    void combine(int node1, int node2) {
        node1 = findRoot(node1);
        node2 = findRoot(node2);
        if(node1 == node2)
            return;

        if(rank[node1] < rank[node2])
            std::swap(node1, node2);

        parent[node2] = node1;

        if(rank[node1] == rank[node2])
            rank[node1] ++;
    }

    bool sameComponent(int node1, int node2) {
        node1 = findRoot(node1);
        node2 = findRoot(node2);
        return (node1 == node2);
    }
};

int main() {
    // std::ios_base::sync_with_stdio(false);
    // std::cin.tie(NULL);
    // std::cout.tie(NULL);

    int V, E;
    fin >> V >> E;

    DSU first(V), second(V);
    int src, dest;
    for(int i = 0; i < E; i ++) {
        fin >> src >> dest;

        if(first.sameComponent(src, dest) == false) {
            edge[src].push_back(dest);
            edge[dest].push_back(src);
            first.combine(src, dest);
        }
        else if(second.sameComponent(src, dest) == false) {
            edge[src].push_back(dest);
            edge[dest].push_back(src);
            second.combine(src, dest);
        }
    }

    for(int i = 1; i <= V; i ++)
        if(visited[i] == false)
            dfs(i, -1);

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Correct 2 ms 2648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 3256 KB Output is correct
2 Correct 8 ms 3020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 276 ms 7932 KB Output is correct
2 Correct 280 ms 7648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 461 ms 7756 KB Output is correct
2 Correct 555 ms 6060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 762 ms 8524 KB Output is correct
2 Correct 655 ms 7724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1114 ms 11864 KB Output is correct
2 Correct 1067 ms 8152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 1690 ms 26192 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2109 ms 18568 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2613 ms 17448 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3291 ms 15644 KB Output is correct
2 Runtime error 3213 ms 65536 KB Memory limit exceeded