#include using namespace std; struct TopologicalSort{ vector rank; vector ordered_indices; bool valid; TopologicalSort(int N, vector G[]){ rank.resize(N, -1); ordered_indices.resize(N, -1); vector indeg(N, 0); for(int i=0; i st; for(int i=0; i> H >> W; for(int i=0; i> A[i]; for(int i=0; i> B[i]; sort(A, A+H); sort(B, B+W); vector edges[400*400]; for(int i=0; i