Pagini recente » Cod sursa (job #2399660) | Cod sursa (job #800472) | Cod sursa (job #1594637) | Cod sursa (job #1171027) | Cod sursa (job #2981447)
#include <bits/stdc++.h>
using namespace std;
#define ll unsigned long long
#define fast_read ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define INF 0x3f3f3f3f3f3f
const int maxn = 1e5;
const int maxm = 2e5;
const int mod = 666013;
ifstream fin("biconex.in");
ofstream fout("biconex.out");
int n, p, m, timp;
vector<int> a[maxn + 2];
int t_in[maxn + 2], t_min[maxn + 2];
stack<int> s;
vector<pair<int, int>> punte;
vector<vector<int>> cbc;
bool artpoint[maxn + 2];
void read(){
fin >> n >> m;
for(int i = 1; i <= m; ++i){
int x, y; fin >> x >> y;
a[x].push_back(y);
a[y].push_back(x);
}
}
void add_cbc(int x, int y, vector<int> & c){
while(s.top() != y){
c.push_back(s.top());
s.pop();
}
c.push_back(y);
c.push_back(x);
s.pop();
}
void dfs(int x, int t){
t_in[x] = t_min[x] = ++timp;
int nrfii = 0;
s.push(x);
for(auto y : a[x]){
if(y == t)
continue;
if(t_in[y] == 0){ // y este fiu in arborele DFS
dfs(y, x);
nrfii++;
t_min[x] = min(t_min[x], t_min[y]);
if(t_min[y] >= t_in[x]){
vector<int> c;
add_cbc(x, y, c);
cbc.push_back(c);
if(t_min[y] > t_in[x]){
punte.push_back({x, y});
}
if(t != 0)
artpoint[x] = 1;
}
}
else{ // am muchie de intoarcere
t_min[x] = min(t_min[x], t_in[y]);
}
}
if(nrfii > 1 && t == 0) artpoint[x] = 1;
}
int main(){
read();
for(int i = 1; i <= n; ++i)
if(!t_in[i])
dfs(i, 0);
fout << cbc.size() << "\n";
for(auto x : cbc){
for(auto y : x) fout << y << " ";
fout << '\n';
}
return 0;
}
/*
task:
*/