SDUT 3304 选课大作战

来源:互联网 发布:ar软件排行 编辑:程序博客网 时间:2024/06/10 04:23

题目描述

眼看着大一新生就要来了,原大一的成了学叔学婶。

   小C又在为了新学期的选课问题忙了起来。。。。。渐渐地他发现了一个问题:当他想学“计算机网络”这门课时,选课系统告诉他必须学过“离散数学”才能学这门科目。

所以我们就称“离散数学”是“计算机网络”的必学科目。现在已知选课系统收集了很多科目的顺序关系,但是,这个选课系统出了一些故障,一些信息可能不准确,所以请你来帮小C判断一下信息是否错误,首先信息错误是指“科目X是科目Y的必学科目,同时科目Y也是科目X的必学科目”,"科目X是科目Y的必学科目,科目Y是科目Z的必学科目,科目Z是科目X的必学科目"这类也是错误的。

输入

 第1行:1个整数T,表示数据的组数T(1 <= T <= 5)

接下来T组数据按照以下格式:
1行:2个整数,N,MN表示课程总数量,课程编号为1..NM表示顺序关系的数量。1 <= N <= 100,000. 1 <= M <= 500,000
2..M+1行:每行2个整数,A,B。表示课程A是课程B的前置课程。

输出

 第1..T行:每行1个字符串,若该组信息无误,输出"Correct",若该组信息有误,输出"Wrong"

示例输入

22 21 22 13 21 21 3

示例输出

WrongCorrect


#include <iostream>#include <stdio.h>#include <string.h>#include <queue>#include <algorithm>#include <stdlib.h>using namespace std;struct node{    int data;    struct node *next;}*head[100010];int rd[100010];int  n,m,x,y;void tuopu(){    int num,i,t;    queue<int>q;    for(i=1;i<=n;i++)    {        if(rd[i]==0)            q.push(i);    }    num=0;    while(!q.empty())    {        t=q.front();        q.pop();        num++;        struct node *p;        p=head[t];        while(p!=NULL)        {            int x=p->data;            rd[x]--;            if(rd[x]==0)                q.push(x);            p=p->next;        }    }    if(num==n)        printf("Correct\n");    else        printf("Wrong\n");}void add(int u,int v){    struct node *p=(struct  node*)malloc(sizeof(struct node));    p->data=v;    p->next=head[u];    head[u]=p;}int main(){    int t;    scanf("%d",&t);    while(t--)    {        memset(head,NULL,sizeof(head));        memset(rd,0,sizeof(rd));        scanf("%d %d",&n,&m);        while(m--)        {            scanf("%d %d",&x,&y);            add(x,y);            rd[y]++;        }        tuopu();    }    return 0;}


0 0
原创粉丝点击