#pragma comment(linker, "/STACK:102400000,102400000") #include #include #include #include using namespace std; const int N = 1000000 + 5; const int M = N * 3; #define min(a, b) ((a) < (b) ? (a) : (b)) int head[N]; int v[M]; int next[M]; int type[M]; int n; int m1, m2; int low[N]; int dfn[N]; int scc_id[N]; int scc_cnt; int id[N]; int stk[N]; int timestamp; int m; bool flag; int edge_cnt; void addEdge(int a, int b, int id) { v[edge_cnt] = b; type[edge_cnt] = id; next[edge_cnt] = head[a]; head[a] = edge_cnt++; } void tarjan(int u) { dfn[u] = low[u] = ++timestamp; stk[++stk[0]] = u; for (int i = head[u]; i != -1; i = next[i]) { if (id[type[i]] >= m) continue; id[type[i]] = m; int w = v[i]; if (dfn[w] == -1) { tarjan(w); if (flag) return; low[u] = min(low[u], low[w]); } else if (scc_id[w] == -1) { low[u] = min(low[u], dfn[w]); } } if (low[u] == dfn[u]) { int num = 0; for (; ; ) { int w = stk[stk[0]--]; scc_id[w] = scc_cnt; num++; if (w == u) break; } scc_cnt++; if (num > 1) { flag = true; } } } void sccTable() { memset(dfn, -1, sizeof(dfn)); stk[0] = 0; memset(scc_id, -1, sizeof(scc_id)); memset(id, -1, sizeof(id)); m = 0; flag = false; for (int i = 0; i < n; i++) { if (dfn[i] == -1) { tarjan(i); m++; if (flag) return; } } } int main(){ int t; int a, b; scanf("%d",&t); while(t--){ edge_cnt=0; memset(head,-1,sizeof head); memset(type,0,sizeof type); scanf("%d%d%d",&n,&m1,&m2); for(int i=0;i