Pagini recente » Cod sursa (job #1067214) | Cod sursa (job #1919221) | Cod sursa (job #159094) | Cod sursa (job #2909031) | Cod sursa (job #1914406)
#include <fstream>
#include <vector>
#include <stack>
#include <algorithm>
#define for0(i,n) for(int i=0; i<n; i++)
#define for1(i,n) for(int i=1; i<=n; i++)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define V vector<int>
#define VP vector<pair<int, int> >
#define clr(A,x) memset(A, x, sizeof(A))
#define cpy(A,B) memcpy(A, B, sizeof(B))
#define g(stream, s) getline(stream, s)
#define FASTIO ios_base::sync_with_stdio(0)
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
const int CHARMAX = (1 << 10);
const int INFINT = 2000000000 + 100;
const ll INFLL = (1LL << 62);
/*class InParsare
{
private:
FILE *fin;
char *buffer;
size_t index_of_buffer;
char read_character()
{
index_of_buffer++;
if(index_of_buffer == CHARMAX)
{
fread(buffer, 1, CHARMAX, fin);
index_of_buffer = 0;
}
return buffer[index_of_buffer];
}
public:
InParsare(const char *name)
{
fin = fopen(name, "r");
buffer = new char[CHARMAX]();
index_of_buffer = CHARMAX - 1;
}
template<class T>
InParsare &operator >> (T &n)
{
char c;
while(!isdigit(c = read_character()) && c != '-');
int sgn = 1;
if(c == '-')
{
n = 0;
sgn = -1;
}
else n = c - '0';
while(isdigit(c = read_character()))
n = n * 10 + c - '0';
n *= sgn;
return *this;
}
};
class OutParsare
{
private:
FILE *fout;
char *buffer;
size_t index_of_buffer;
void write_character(char character)
{
if(index_of_buffer == CHARMAX)
{
fwrite(buffer, 1, CHARMAX, fout);
index_of_buffer = 0;
buffer[index_of_buffer++] = character;
}
else buffer[index_of_buffer++] = character;
}
public:
OutParsare(const char *name)
{
fout = fopen(name, "w");
buffer = new char[CHARMAX]();
index_of_buffer = 0;
}
~OutParsare()
{
fwrite(buffer, 1, index_of_buffer, fout);
fclose(fout);
}
template<class T>
OutParsare &operator << (T n)
{
if(typeid(T).name() == typeid(char).name())
{
write_character(n);
return *this;
}
if(n <= 9)
write_character(n + '0');
else
{
(*this) << (n / 10);
write_character(n % 10 + '0');
}
return *this;
}
};*/
//InParsare fin("zoo.in"); /// merg numai pt numere
//OutParsare fout("zoo.out"); /// merg numai pt numere + caractere individuale, nu stringuri
ifstream fin("biconex.in");
ofstream fout("biconex.out");
const int NMAX = 1e5 + 1;
const int MOD = 666013;
const double EPS = 0.000000001;
int n, m;
V graf[NMAX];
bool viz[NMAX];
int niv[NMAX], low[NMAX];
vector<int> temp;
vector<vector<int> > sol;
stack<pair<int, int> > coada;
void dfs(int nod = 1, int p = 0)
{
// cout << nod << '\n';
viz[nod] = 1;
low[nod] = niv[nod] = niv[p] + 1;
for(auto i: graf[nod])
{
if(p == nod)
continue;
if(viz[i])
{
low[nod] = min(low[nod], niv[i]);
continue;
}
coada.push({nod, i});
dfs(i, nod);
if(low[i] >= niv[nod])
{
temp.clear();
int a, b;
do
{
a = coada.top().first, b = coada.top().second;
coada.pop();
temp.pb(a);
temp.pb(b);
}while(a != nod && b != i);
sol.pb(temp);
}
low[nod] = min(low[nod], low[i]);
}
}
int main()
{
fin >> n >> m;
for1(i, m)
{
int a, b;
fin >> a >> b;
graf[a].pb(b);
graf[b].pb(a);
}
dfs();
fout << sol.size() << '\n';
for(auto it: sol)
{
sort(all(it));
it.erase(unique(all(it)), it.end());
for(auto i: it)
fout << i << ' ';
fout << '\n';
}
return 0;
}