Submission #95868

# Submission time Handle Problem Language Result Execution time Memory
95868 2019-02-03T09:07:55 Z Kastanda Pipes (CEOI15_pipes) C++11
100 / 100
3128 ms 9592 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 > 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 (ts >= M + M - 40)
            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 4 ms 2688 KB Output is correct
2 Correct 3 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 2816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 153 ms 4600 KB Output is correct
2 Correct 150 ms 4380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 268 ms 5052 KB Output is correct
2 Correct 316 ms 4476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 480 ms 6088 KB Output is correct
2 Correct 422 ms 5624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 751 ms 8568 KB Output is correct
2 Correct 613 ms 5112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1298 ms 9000 KB Output is correct
2 Correct 1090 ms 7228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1923 ms 9592 KB Output is correct
2 Correct 1670 ms 5428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2499 ms 9560 KB Output is correct
2 Correct 2360 ms 5496 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3128 ms 9348 KB Output is correct
2 Correct 2324 ms 7928 KB Output is correct