#include<stdio.h> #include<stack> namespace bikuhiku{ template <typename _T> _T gtr(_T &_compare_x,_T &_compare_y) { return _compare_x > _compare_y ? _compare_x : _compare_y; } template <typename _T> _T les(_T &_compare_x,_T &_compare_y) { return _compare_x < _compare_y ? _compare_x : _compare_y; } template <typename _T> void get_int(_T &_data_x) { int _signal = 1; char _get_c; _data_x = 0; for(_get_c = getchar();_get_c < '0'||_get_c > '9';_get_c = getchar()) if(_get_c == '-') _signal = -1; for(;_get_c >= '0'&&_get_c <= '9';_get_c = getchar()) _data_x = (_data_x<<3)+(_data_x<<1)+(_get_c^48); _data_x *= _signal; return; } template <typename _T> void put_int(_T _data_x) { if(_data_x > 9) put_int(_data_x/10); putchar((_data_x%10)^48); return; } }//申请一块命名空间; using namespace bikuhiku; using namespace std; const int z = 16384-4096-2048; struct line{ int t, next; } edge[z*5]; int cnt, head[z]; void adline(int &f,int &t) { edge[++cnt].next = head[f]; edge[cnt].t = t; head[f] = cnt; return; } stack<int> stk; int dfn[z], low[z], time; int belong[z]; bool instk[z]; void tarjan(int &u) { dfn[u] = low[u] = ++time; stk.push(u); instk[u] = true; for(int i = head[u];i;i = edge[i].next) { if(!dfn[edge[i].t]) {//是树枝边; tarjan(edge[i].t); low[u] = les(low[u],low[edge[i].t]); } else if(instk[edge[i].t]) {//是返祖边; low[u] = les(low[u],dfn[edge[i].t]); } } if(low[u] == dfn[u]) {//构成强连通分量; int tmp; ++belong[0]; do { tmp = stk.top(); stk.pop(); instk[tmp] = false; belong[tmp] = belong[0]; } while(tmp != u); } return; } int main() { //to do; return 0; }