Pagini recente » Cod sursa (job #236779) | Cod sursa (job #1934544) | Cod sursa (job #484446) | Cod sursa (job #2674456) | Cod sursa (job #2689847)
//ALEXANDRU MICLEA
#include <vector>
#include <algorithm>
#include <string>
#include <string.h>
#include <cstring>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <time.h>
#include <iomanip>
#include <deque>
#include <math.h>
#include <cmath>
#include <assert.h>
#include <stack>
#include <bitset>
#include <random>
#include <chrono>
#include <assert.h>
using namespace std;
using ll = long long;
#include <fstream>
//ifstream cin("input.in"); ofstream cout("output.out");
ifstream cin("biconex.in"); ofstream cout("biconex.out");
//VARIABLES
const int maxn = 1e5 + 5;
vector <vector <int>> gr(maxn);
vector <int> ans[maxn];
int used[maxn], tin[maxn], low[maxn];
stack <int> s;
int timer = 0, cont = 0;;
//FUNCTIONS
void dfs (int nod, int p){
used[nod] = true;
tin[nod] = low[nod] = timer++;
s.push(nod);
for (auto& x : gr[nod]){
if (used[x]) low[nod] = min(low[nod] , tin[x]);
else {
dfs(x, nod);
low[nod] = min(low[nod], low[x]);
if (low[x] >= tin[nod]){
cont++;
while (s.top() != x){
ans[cont].push_back(s.top());
s.pop();
}
ans[cont].push_back(x);
ans[cont].push_back(nod);
s.pop();
}
}
}
}
//MAIN
int main() {
int n, m; cin >> n >> m;
for (int i = 1; i <= m; i++){
int a, b; cin >> a >> b;
gr[a].push_back(b);
gr[b].push_back(a);
}
for (int i = 1; i <= n; i++){
tin[i] = -1;
low[i] = -1;
}
for (int i = 1; i <= n; i++){
if (!used[i]) dfs(i, 0);
}
cout << cont << '\n';
for (int i = 1; i <= cont; i++){
for (auto& el : ans[i]){
cout << el << ' ';
}
cout << '\n';
}
return 0;
}