답안 #585581

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
585581 2022-06-29T05:43:11 Z 1zaid1 Pipes (CEOI15_pipes) C++17
0 / 100
1814 ms 65536 KB
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
const int M = 1e5+1;
vector<int> node[M];
int a[M], d[M], tt = 1;
bitset<100005> vis;
vector<pair<int, int>> ans;

void dfs(int s) {
    a[s] = tt++;
    vis[s] = true;
    for (int i:node[s]) if (!vis[i]) dfs(i);
    d[s] = tt++;
}

void dfs2(int s, int p = 1) {
    vis[s] = true;
    for (int i:node[s]) {
        if (!vis[i]) dfs2(i, s);
        if (i != p) a[s] = min(a[s], a[i]);
        if (i != p) d[s] = max(d[s], d[i]);
    }
}

void dfs3(int s) {
    vis[s] = true;
    for (int i:node[s]) {
        if (!vis[i]) {
            if (d[i] < d[s] && a[i] > a[s]) ans.push_back({s, i});
            dfs3(i);
        }
    }
}

signed main() {
    cin.tie(0)->sync_with_stdio(0);
    
    int n, m;
    cin >> n >> m;

    for (int i = 1; i <= m; i++) {
        int a, b;
        cin >> a >> b;

        node[a].push_back(b);
        node[b].push_back(a);
    }

    for (int i = 1; i <= n; i++) if (!vis[i]) dfs(i); vis = 0;
    for (int i = 1; i <= n; i++) if (!vis[i]) dfs2(i); vis = 0;
    for (int i = 1; i <= n; i++) if (!vis[i]) dfs3(i); vis = 0;
    for (auto [a, b]:ans) cout << a << ' ' << b << endl;

    return 0;
}
/*
10 11
1 7
1 8
1 6
2 8
6 7
5 8
2 5
2 3
2 4
3 4
10 9

*/

Compilation message

pipes.cpp: In function 'int main()':
pipes.cpp:50:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   50 |     for (int i = 1; i <= n; i++) if (!vis[i]) dfs(i); vis = 0;
      |     ^~~
pipes.cpp:50:55: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   50 |     for (int i = 1; i <= n; i++) if (!vis[i]) dfs(i); vis = 0;
      |                                                       ^~~
pipes.cpp:51:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   51 |     for (int i = 1; i <= n; i++) if (!vis[i]) dfs2(i); vis = 0;
      |     ^~~
pipes.cpp:51:56: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   51 |     for (int i = 1; i <= n; i++) if (!vis[i]) dfs2(i); vis = 0;
      |                                                        ^~~
pipes.cpp:52:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   52 |     for (int i = 1; i <= n; i++) if (!vis[i]) dfs3(i); vis = 0;
      |     ^~~
pipes.cpp:52:56: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   52 |     for (int i = 1; i <= n; i++) if (!vis[i]) dfs3(i); vis = 0;
      |                                                        ^~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 2644 KB Wrong number of edges
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 3284 KB Wrong number of edges
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 101 ms 16332 KB Wrong number of edges
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 208 ms 23912 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 398 ms 41612 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 682 ms 52096 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1098 ms 65536 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1416 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1561 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1814 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -