답안 #585580

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
585580 2022-06-29T05:42:35 Z 1zaid1 Pipes (CEOI15_pipes) C++17
컴파일 오류
0 ms 0 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], tm = 1;
bitset<100005> vis;
vector<pair<int, int>> ans;

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

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 'void dfs(int)':
pipes.cpp:11:12: error: reference to 'tm' is ambiguous
   11 |     a[s] = tm++;
      |            ^~
In file included from /usr/include/time.h:39,
                 from /usr/include/c++/10/ctime:42,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:49,
                 from pipes.cpp:1:
/usr/include/x86_64-linux-gnu/bits/types/struct_tm.h:7:8: note: candidates are: 'struct tm'
    7 | struct tm
      |        ^~
pipes.cpp:6:17: note:                 'int tm'
    6 | int a[M], d[M], tm = 1;
      |                 ^~
pipes.cpp:14:12: error: reference to 'tm' is ambiguous
   14 |     d[s] = tm++;
      |            ^~
In file included from /usr/include/time.h:39,
                 from /usr/include/c++/10/ctime:42,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:49,
                 from pipes.cpp:1:
/usr/include/x86_64-linux-gnu/bits/types/struct_tm.h:7:8: note: candidates are: 'struct tm'
    7 | struct tm
      |        ^~
pipes.cpp:6:17: note:                 'int tm'
    6 | int a[M], d[M], tm = 1;
      |                 ^~
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;
      |                                                        ^~~