namespace RST
{
vector<int> G[MAX],T[MAX<<1];
int dfn[MAX],low[MAX],tot;
int stk[MAX],top,num;
void tarjan(int now)
{
dfn[now]=low[now]=++tot;
stk[++top]=now;
for(auto to:G[now])
if(!dfn[to])
{
tarjan(to),cmin(low[now],low[to]);
if(low[to]==dfn[now])
{
++num;
do T[num].eb(stk[top]),T[stk[top]].eb(num),--top; while(stk[top+1]!=to);
T[num].eb(now),T[now].eb(num);
}
}
else cmin(low[now],dfn[to]);
}
inline void build() {for(int i=1;i<=n;++i) if(!dfn[i]) tarjan(i);}
}