#include <vector>
#include <iostream>
#include <bitset>
using namespace std;
typedef vector<int> vi;
#define pb push_back
#define REP(i, a, b) for(int i = a; i < b; i++)
#define MAXN 100005
vi adj[MAXN];
int h[MAXN], crossEdges[MAXN], par[MAXN];
bitset<MAXN> visited;
void dfs(int x) {
visited[x] = true;
for(auto i: adj[x]) if(!visited[i]) {
par[i]=x;
h[i]=h[x]+1;
dfs(i);
}
}
int dp(int x) {
for(auto i:adj[x]) if(par[i]==x) crossEdges[x]+=dp(i);
return crossEdges[x];
}
int main() {
int N, E, A, B, ans; cin >> N >> E;
REP(i,0,E) {
cin >> A >> B;
adj[A].pb(B);
adj[B].pb(A);
}
REP(i,1,N+1)if(!visited[i]) dfs(i);
REP(i,1,N+1) visited[i]=0;
REP(i,1,N+1) for(auto j: adj[i]) {
if(h[i]>h[j]) crossEdges[i]++;
else crossEdges[i]--;
}
REP(i,1,N+1) if(par[i]&&dp(i)==1) cout << i << " " << par[i] << "\n";
}
Compilation message
pipes.cpp: In function 'int main()':
pipes.cpp:25:18: warning: unused variable 'ans' [-Wunused-variable]
25 | int N, E, A, B, ans; cin >> N >> E;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2904 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
143 ms |
3164 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5067 ms |
10836 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5036 ms |
14160 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5029 ms |
24656 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5069 ms |
29512 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5027 ms |
65536 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5065 ms |
65536 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1866 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2025 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |