/*
_________ .---""" """---.
:______.-': : .--------------. :
| ______ | | : : |
|:______B:| | | Little Error: | |
|:______B:| | | | |
|:______B:| | | Power not | |
| | | | found. | |
|:_____: | | | | |
| == | | : : |
| O | : '--------------' :
| o | :'---...______...---'
| o |-._.-i___/' \._
|'-.____o_| '-. '-...______...-' `-._
:_________: `.____________________ `-.___.-.
.'.eeeeeeeeeeeeeeeeee.'. :___:
fsc .'.eeeeeeeeeeeeeeeeeeeeee.'.
:____________________________:
*/
//in the name of god
//if you read this code please search about imam hussain
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define endl "\n"
#define X first
#define Y second
#define pii pair<int,int>
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define read freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout)
const int maxn=1e5+5;
const int mod=1e9+7;
const int inf=1e9;
const int del=728729;
ll poww(ll a, ll b, ll md) {return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));}
int par[maxn][2] ;
int mark[maxn] ;
int an;
vector<int>adj[maxn];
int n ;
int m ;
int getPar(int v){
if(par[v][an] == v){
return v ;
}else return par[v][an] = getPar(par[v][an]);
}
bool merge(int u, int v){
u = getPar(u);
v = getPar(v);
if (u == v){
return false;
}
par[u][an] = v;
return true;
}
void dfs(int v, int p = 0){
mark[v] = 1;
par[v][1] = maxn;
int cnt = 0 ;
for (int u : adj[v]){
if (u == p){
cnt ++;
continue;
}
if (mark[u]){
par[v][1] = min(par[v][1], par[u][0]);
}
else{
par[u][0] = par[v][0] + 1;
dfs(u, v);
par[v][1] = min(par[v][1], par[u][1]);
}
}
if (p and cnt == 1 and par[p][0] < par[v][1]){
cout << p << " " << v << endl;
}
}
int main(){
migmig ;
cin >> n >> m;
for (int i = 0; i < maxn; i ++){
par[i][0] = par[i][1] = i;
}
for (int i = 0; i < m; i ++){
int u ;
int v ;
bool flag = true;
cin >> u >> v;
an = 0;
if (merge(u, v)){
adj[u].pb(v);
adj[v].pb(u);
flag = 0;
}
an = 1;
if (flag and merge(u, v)){
adj[u].pb(v);
adj[v].pb(u);
}
}memset(par, 0, sizeof par);
for (int v = 1; v <= n; v ++){
if (!mark[v]){
dfs(v);
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
3456 KB |
Output is correct |
2 |
Correct |
2 ms |
3404 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
3788 KB |
Output is correct |
2 |
Correct |
8 ms |
3660 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
115 ms |
3708 KB |
Output is correct |
2 |
Correct |
109 ms |
3568 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
190 ms |
4204 KB |
Output is correct |
2 |
Correct |
221 ms |
3908 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
330 ms |
5508 KB |
Output is correct |
2 |
Correct |
301 ms |
5200 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
457 ms |
9848 KB |
Output is correct |
2 |
Correct |
394 ms |
6980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
718 ms |
10848 KB |
Output is correct |
2 |
Correct |
647 ms |
8388 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
935 ms |
12560 KB |
Output is correct |
2 |
Correct |
847 ms |
8480 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1121 ms |
12672 KB |
Output is correct |
2 |
Correct |
1045 ms |
8516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1333 ms |
12092 KB |
Output is correct |
2 |
Runtime error |
1249 ms |
20904 KB |
Memory limit exceeded |