Submission #95867

# Submission time Handle Problem Language Result Execution time Memory
95867 2019-02-03T09:05:48 Z Kastanda Pipes (CEOI15_pipes) C++11
100 / 100
3168 ms 9564 KB
#include<bits/stdc++.h>
using namespace std;
const int N = 100005, M = N * 2;
int n, H[N], Mn[N];
int ts, head[N], nxt[M + M];
int m, from[M], to[M];
bitset < M + M > tree, bridge;
bitset < N > mark;
inline void AddEdge(int v, int u)
{
    from[ts >> 1] = v; to[ts >> 1] = u;
    nxt[ts] = head[v]; head[v] = ts;
    nxt[ts|1] = head[u]; head[u] = ts|1;
    ts += 2;
}
void DFS(int v, int p)
{
    mark[v] = 1;
    Mn[v] = H[v];
    for (int e = head[v]; e != -1; e = nxt[e])
        if ((e >> 1) != p)
        {
            int u = from[e >> 1] ^ to[e >> 1] ^ v;
            if (mark[u])
                Mn[v] = min(Mn[v], H[u]), bridge[e >> 1] = 0;
            else
            {
                H[u] = H[v] + 1;
                DFS(u, e >> 1);
                Mn[v] = min(Mn[v], Mn[u]);
                tree[e >> 1] = 1;
                if (Mn[u] < H[u])
                    bridge[e >> 1] = 0;
            }
        }
}
inline void Unlaze()
{
    mark = 0; tree = 0;
    memset(H, 0, sizeof(H));
    for (int i = 1; i <= n; i++)
        if (!mark[i])
            DFS(i, -1);
    int cnt = 0;
    for (int i = 0; i < (ts >> 1); i++)
        if (tree[i])
        {
            bool a;
            a = tree[i];
            tree[i] = tree[cnt];
            tree[cnt] = a;

            a = bridge[i];
            bridge[i] = bridge[cnt];
            bridge[cnt] = a;

            swap(from[i], from[cnt]);
            swap(to[i], to[cnt]);
            cnt ++;
        }
    ts = 0;
    memset(nxt, -1, sizeof(nxt));
    memset(head, -1, sizeof(head));
    for (int i = 0; i < cnt; i++)
        AddEdge(from[i], to[i]);
}
int main()
{
    memset(nxt, -1, sizeof(nxt));
    memset(head, -1, sizeof(head));
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= m; i++)
    {
        int v, u;
        scanf("%d%d", &v, &u);
        bridge[ts >> 1] = 1;
        AddEdge(v, u);
        if (i % N == 0)
            Unlaze();
    }
    Unlaze();
    for (int i = 0; i < (ts >> 1); i++)
        if (bridge[i])
            printf("%d %d\n", from[i], to[i]);
    return 0;
}

Compilation message

pipes.cpp: In function 'int main()':
pipes.cpp:71:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~
pipes.cpp:75:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &v, &u);
         ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2736 KB Output is correct
2 Correct 4 ms 2688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 3072 KB Output is correct
2 Correct 6 ms 2944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 147 ms 3832 KB Output is correct
2 Correct 145 ms 3664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 270 ms 4380 KB Output is correct
2 Correct 312 ms 3788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 471 ms 5364 KB Output is correct
2 Correct 377 ms 4852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 806 ms 8116 KB Output is correct
2 Correct 696 ms 4940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1541 ms 8548 KB Output is correct
2 Correct 1193 ms 6996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1973 ms 9564 KB Output is correct
2 Correct 1680 ms 5452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2622 ms 9560 KB Output is correct
2 Correct 2291 ms 5448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3168 ms 9316 KB Output is correct
2 Correct 2508 ms 7788 KB Output is correct