Pagini recente » Istoria paginii runda/dedicatie_speciala/clasament | Cod sursa (job #1372272) | Cod sursa (job #1873891) | Cod sursa (job #306522) | Cod sursa (job #2720640)
#include <bits/stdc++.h>
#define Nmax 100005
using namespace std;
ifstream fin("biconex.in");
ofstream fout("biconex.out");
int N, M, K;
int dp[Nmax], h[Nmax];
bool vis[Nmax];
vector<int> G[Nmax], ans[Nmax], nodes;
void MakeComp(int node, int last) {
++K;
while (nodes.back() != last)
ans[K].push_back(nodes.back()), nodes.pop_back();
ans[K].push_back(node);
}
void DFS(int node, int father) {
vis[node] = 1;
h[node] = dp[node] = h[father] + 1;
nodes.push_back(node);
// cout << node << " " << father << '\n';
for (auto it: G[node])
if (vis[it] == 0) { ///son
int last = nodes.back();
DFS(it, node);
dp[node] = min(dp[node], dp[it]);
if (dp[it] >= h[node]) MakeComp(node, last);
}
else if (it != father) dp[node] = min(dp[node], h[it]); ///back-edge
}
int main()
{
fin >> N >> M;
while (M--) {
int x, y;
fin >> x >> y;
G[x].push_back(y);
G[y].push_back(x);
}
DFS(1, 0);
fout << K << '\n';
for (int i = 1; i <= K; ++i) {
for (auto it: ans[i])
fout << it << " ";
fout << '\n';
}
return 0;
}