1174 : 拓扑排序·一
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
using namespace std;
const int N = 100005;
int indx[N];
vector<int>G[N];
int topsort(int n)
{
int ans=0;
queue<int>q;
for(int i=1;i<=n;i++){
if(indx[i]==0){
q.push(i);
ans++;
}
}
while(!q.empty()){
int fp=q.front();
q.pop();
for(int i=0;i<G[fp].size();i++){
int v = G[fp][i];
indx[v]--;
if(indx[v]==0){
q.push(v);
ans++;
}
}
}
return ans;
}
int main()
{
int T;
scanf("%d",&T);
while(T--){
int n,m;
memset(indx,0,sizeof(indx));
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++){
G[i].clear();
}
for(int i=1;i<=m;i++){
int u,v;
scanf("%d%d",&u,&v);
G[u].push_back(v);
indx[v]++;
}
int ans=0;
ans=topsort(n);
if(ans==n)
printf("Correct\n");
else
printf("Wrong\n");
}
return 0;
}