Pagini recente » Cod sursa (job #3222739) | Cod sursa (job #705275) | Cod sursa (job #3223201) | Cod sursa (job #3222908) | Cod sursa (job #1394321)
#include <vector>
#include <algorithm>
#include <fstream>
using namespace std;
ifstream f("biconex.in");
ofstream g("biconex.out");
int k, t , i, p, q;
int H[100005], up[100005];
bool viz[100005];
int stiva[2][100005];
vector <int> V[100005], S[100005];
vector <int>::iterator it;
void citire(){
f >> t >> t;
for (i = 1; i <= t; i++) {
f>>p>>q;
V[p].push_back(q);
V[q].push_back(p);
}
}
void dfs(int nod) {
viz[nod] = true;
up[nod] = H[nod];
for (vector <int>::iterator it = V[nod].begin(); it != V[nod].end(); ++it)
if (viz[*it] == false){
H[*it] = H[nod] + 1;
stiva[0][++t] = nod;
stiva[1][t] = *it;
dfs(*it);
if (up[*it] >= H[nod]) {
k++;
while (!(stiva[0][t] == nod && stiva[1][t] == *it)) {
S[k].push_back(stiva[1][t]);
t--;
}
S[k].push_back(nod);
S[k].push_back(*it);
t--;
}
up[nod] = min(up[nod], up[*it]);
}
else
up[nod] = min(up[nod], H[*it]);
}
void afisare() {
g << k << '\n';
for(i = 1; i <= k; i++){
for(it = S[i].begin(); it != S[i].end(); ++it)
g << *it << " ";
g << '\n';
}
}
int main() {
citire();
dfs(1);
afisare();
}