#include <bits/stdc++.h>
using namespace std;
#define ll int
#define ii pair<ll,ll>
#define endl '\n'
const ll inf=1e15;
const ll mod=1e9+7;
const ll maxn=1e5+5;
vector<ll> adj[maxn];
ll cnt[maxn],depth[maxn],low[maxn];
ll par[maxn][2];
int root(ll x, ll l){
if (par[x][l]==x) return x;
return par[x][l]=root(par[x][l],l);
}
bool connect(ll a, ll b, ll l){
if (root(a,l)==root(b,l)) return 0;
par[root(a,l)][l]=root(b,l);
return 1;
}
void dfs(ll node, ll p){
for (auto &u:adj[node]){
if (depth[u]==-1){
depth[u]=depth[node]+1;
dfs(u,node);
if (low[u]>depth[node]){
cout<<node<<' '<<u<<endl;
}
low[node]=min(low[node],low[u]);
} else if (u!=p){
low[node]=min(low[node],depth[u]);
}
}
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
ll n,e,a,b;
cin>>n>>e;
for (int i=0;i<maxn;i++) low[i]=inf;
memset(depth,-1,sizeof(depth));
for (int i=0;i<maxn;i++){
par[i][0]=i;
par[i][1]=i;
}
for (int i=0;i<e;i++){
cin>>a>>b;
if (connect(a,b,0) || connect(a,b,1)){
adj[a].emplace_back(b);
adj[b].emplace_back(a);
}
}
vector<ll> v;
for (int i=1;i<=n;i++){
sort(adj[i].begin(),adj[i].end());
v.clear();
for (auto u:adj[i]){
if (v.empty()) v.emplace_back(u);
if (v.back()==u){
while (v.size() && v.back()==u) v.pop_back();
} else v.push_back(u);
}
swap(v,adj[i]);
} //remove duplicates
for (int i=1;i<=n;i++){
if (depth[i]!=-1) continue;
depth[i]=1;
dfs(i,-1);
}
return 0;
}
Compilation message
pipes.cpp:7:14: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+15' to '2147483647' [-Woverflow]
7 | const ll inf=1e15;
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
4172 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
4300 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
82 ms |
4300 KB |
Output is correct |
2 |
Incorrect |
79 ms |
4300 KB |
Wrong number of edges |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
137 ms |
4556 KB |
Output is correct |
2 |
Incorrect |
181 ms |
6100 KB |
Wrong number of edges |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
269 ms |
5068 KB |
Output is correct |
2 |
Incorrect |
211 ms |
5204 KB |
Wrong number of edges |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
341 ms |
6928 KB |
Output is correct |
2 |
Incorrect |
302 ms |
6924 KB |
Wrong number of edges |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
514 ms |
7468 KB |
Output is correct |
2 |
Incorrect |
459 ms |
7100 KB |
Wrong number of edges |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
664 ms |
8220 KB |
Output is correct |
2 |
Incorrect |
627 ms |
8244 KB |
Wrong number of edges |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
795 ms |
8168 KB |
Output is correct |
2 |
Incorrect |
797 ms |
8140 KB |
Wrong number of edges |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1043 ms |
8000 KB |
Output is correct |
2 |
Incorrect |
1040 ms |
7596 KB |
Wrong number of edges |
3 |
Halted |
0 ms |
0 KB |
- |