#include <bits/stdc++.h>
using namespace std;
#define scd(t) scanf("%d", &t)
#define sclld(t) scanf("%lld", &t)
#define forr(i, j, k) for (int i = j; i < k; i++)
#define frange(i, j) forr(i, 0, j)
#define all(cont) cont.begin(), cont.end()
#define mp make_pair
#define pb push_back
#define f first
#define s second
typedef long long int lli;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<lli> vll;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<vi> vvi;
typedef map<int, int> mpii;
typedef set<int> seti;
typedef multiset<int> mseti;
typedef long double ld;
void usaco()
{
freopen("/media/hariaakash646/785EF1075EF0BF46/CompetitiveProgramming/input.in", "r", stdin);
// freopen("problem.out", "w", stdout);
}
vvi graph;
vi dis1, dis2;
int findf(int x, vi &dis) {
if(x == dis[x]) return x;
dis[x] = findf(dis[x], dis);
return dis[x];
}
void unionf(int x, int y, vi &dis) {
x = findf(x, dis);
y = findf(y, dis);
dis[y] = x;
}
vii bridg;
vi num, lowpt;
int timer=0;
void dfs(int x, int p) {
num[x] = ++timer;
lowpt[x] = num[x];
int c = 0;
for(auto e : graph[x]) {
if(e == p) {
if(c == 0) {c++;continue;}
}
if(num[e]) lowpt[x] = min(lowpt[x], num[e]);
else {
dfs(e, x);
lowpt[x] = min(lowpt[x], lowpt[e]);
// if(lowpt[e] > num[x]) bridg.pb(mp(x, e));
}
}
if(p && lowpt[x] > num[p]) bridg.pb(mp(p, x));
}
int main() {
// usaco();
int n, m;
scd(n);
scd(m);
graph = vvi(n+1);
dis1 = dis2 = vi(n+1);
forr(i, 1, n+1) {
dis1[i] = dis2[i] = i;
}
frange(i, m) {
int a, b;
scd(a);
scd(b);
if(findf(a, dis1) != findf(b, dis1)) {
unionf(a, b, dis1);
graph[a].pb(b);
graph[b].pb(a);
}
else if(findf(a, dis2) != findf(b, dis2)) {
unionf(a, b, dis2);
graph[a].pb(b);
graph[b].pb(a);
}
// graph[a].pb(b);
// graph[b].pb(a);
}
lowpt = num = vi(n+1);
forr(i, 1, n+1) {
if(!num[i]) dfs(i, 0);
}
for(auto p : bridg) printf("%d %d\n", p.f, p.s);
}
Compilation message
pipes.cpp: In function 'void usaco()':
pipes.cpp:30:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
30 | freopen("/media/hariaakash646/785EF1075EF0BF46/CompetitiveProgramming/input.in", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pipes.cpp: In function 'int main()':
pipes.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
5 | #define scd(t) scanf("%d", &t)
| ~~~~~^~~~~~~~~~
pipes.cpp:77:5: note: in expansion of macro 'scd'
77 | scd(n);
| ^~~
pipes.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
5 | #define scd(t) scanf("%d", &t)
| ~~~~~^~~~~~~~~~
pipes.cpp:78:5: note: in expansion of macro 'scd'
78 | scd(m);
| ^~~
pipes.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
5 | #define scd(t) scanf("%d", &t)
| ~~~~~^~~~~~~~~~
pipes.cpp:88:9: note: in expansion of macro 'scd'
88 | scd(a);
| ^~~
pipes.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
5 | #define scd(t) scanf("%d", &t)
| ~~~~~^~~~~~~~~~
pipes.cpp:89:9: note: in expansion of macro 'scd'
89 | scd(b);
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
860 KB |
Output is correct |
2 |
Correct |
3 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
86 ms |
668 KB |
Output is correct |
2 |
Correct |
82 ms |
652 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
173 ms |
1624 KB |
Output is correct |
2 |
Correct |
172 ms |
6988 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
238 ms |
3648 KB |
Output is correct |
2 |
Runtime error |
215 ms |
17200 KB |
Memory limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
317 ms |
9808 KB |
Output is correct |
2 |
Runtime error |
288 ms |
24608 KB |
Memory limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
560 ms |
16416 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
657 ms |
57748 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
832 ms |
65536 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
994 ms |
65536 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |