이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
const int M = 1e5+1;
vector<int> node[M];
int a[M], l[M], tt = 1;
bitset<100005> vis;
void dfs(int s, int p = 1) {
a[s] = tt++;
l[s] = a[s];
vis[s] = true;
for (int i:node[s]) {
if (!vis[i]) {
dfs(i, s);
if (a[s] < l[i]) cout << s << ' ' << i << endl;
}
}
for (int i:node[s]) if (i != p) l[s] = min(l[s], l[i]);
}
int pr[M], pb[M], rnk[M], bnk[M];
void uniR(int a, int b) {
if (rnk[a] < rnk[b]) swap(a, b);
if (rnk[a] == rnk[b]) rnk[a]++;
pr[b] = a;
}
void uniB(int a, int b) {
if (bnk[a] < bnk[b]) swap(a, b);
if (bnk[a] == bnk[b]) bnk[a]++;
pb[b] = a;
}
int findR(int s) {
return (s==pr[s]?s:pr[s]=findR(pr[s]));
}
int findB(int s) {
return (s==pb[s]?s:pb[s]=findB(pb[s]));
}
signed main() {
cin.tie(0)->sync_with_stdio(0);
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++) pb[i] = pr[i] = i;
for (int i = 1; i <= m; i++) {
int a, b;
cin >> a >> b;
// if (findB(a) == findB(b) && findR(a) == findR(b)) continue;
node[a].push_back(b);
node[b].push_back(a);
// if (findR(a) != findR(b)) uniR(a, b);
// else uniB(a, b);
}
for (int i = 1; i <= n; i++) if (!vis[i]) dfs(i); vis = 0;
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
*/
컴파일 시 표준 에러 (stderr) 메시지
pipes.cpp: In function 'int main()':
pipes.cpp:62:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
62 | for (int i = 1; i <= n; i++) if (!vis[i]) dfs(i); vis = 0;
| ^~~
pipes.cpp:62:55: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
62 | for (int i = 1; i <= n; i++) if (!vis[i]) dfs(i); vis = 0;
| ^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |