# Cod sursa(job #632334)

Utilizator Data 10 noiembrie 2011 21:23:03 Componente tare conexe 100 cpp done Arhiva educationala 1.86 kb
``````#include <iostream>
#include <fstream>
#include <stack>
#include <vector>
#include <iterator>
#include <algorithm>

using namespace std;

const char iname[] = "ctc.in";
const char oname[] = "ctc.out";

#define MAXN  100005
#define Min(a, b)  ((a) < (b) ? (a) : (b))

vector < vector <int> > C;

stack <int> S;

int indecs;

{
ifstream in(iname);
int cnt_edges, x, y;

in >> n;
for (in >> cnt_edges; cnt_edges > 0; -- cnt_edges)
in >> x >> y,
in.close();
}

void print_out(const vector < vector <int> >& G, const char oname[])
{
ofstream out(oname);

out << G.size() << "\n";
for (size_t i = 0; i < G.size(); ++ i) {
for (size_t j = 0; j < G[i].size(); ++ j)
out << G[i][j] + 1 << " ";
out << "\n";
}
out.close();
}

void tarjan(const int n, const vector <int>* adj)
{
indecs ++;
S.push(n), in_stack[n] = 1;

vector <int>::const_iterator it;
if (idx[*it] == -1)
else if (in_stack[*it])
}
con.clear();
int node;
do {
con.push_back(node = S.top());
S.pop(), in_stack[node] = 0;
}
while (node != n);
C.push_back(con);
}
}

int main(void)
{
int n;

idx.assign(n, -1), in_stack.assign(n, 0);
for (int i = 0; i < n; ++ i) if (idx[i] == -1)