Hihocoder 1174 topology Sequencing • One

Source: Internet
Author: User

Topology sequencing • Time limit: 10000ms single point duration: 1000ms memory limit: 256MB description

As the teacher in class today is particularly boring, little hi and small ho secretly chat up.

Little ho: Little Hi, do you have any classes to choose this semester?

Small hi: Quite a lot, such as xxx1,xxx2 and XXX3. Originally wanted to choose YYY2, but did not seem to choose YYY1 First, can not choose YYY2.

Little ho: The first course is a real hassle.

Little hi: Yes. Many courses have first-class courses, and each time you choose a course, you have to check first. The academic records of the first course published are many years ago, not only have duplicate information, it seems that many are not correct.

Little ho: There are too many courses, and the Dean can't tidy it up. They couldn't make a single confirmation that there was a mistake.

Little hi: This is not the time for you to be a little ho!

Little ho: eh??

We all know that college courses can be chosen by themselves, and each semester is free to choose which courses to study. The only restriction is that we have a sequential relationship between courses: some of the most difficult courses may require some pre-set courses. For example, course A is a pre-set course for Course B and requires a course to be completed before a B course can be selected. The university's dean collects the sequential relationships of all courses, but there may be some information errors due to system failures. Now little Ho will tell you the information, please help small ho to determine whether the information is wrong. The wrong information mainly refers to the situation where "course a is a pre-course for Course B, and course B is a pre-curriculum for course a". Course A is a pre-set course for Course B, course B is a pre-curriculum for Course C, and course C is a pre-curriculum for course A, which is also wrong.

Hint: Topology ordering

Input

Line 1th: An integer t that represents the number of groups of data T (1 <= t <= 5)
Next the T Group data is in the following format:
Line 1th: 2 integers, n,m. n indicates the total number of courses and the course number is 1. N. M represents the number of sequential relationships. 1 <= N <= 100,000. 1 <= M <= 500,000
2nd.. M+1 line: 2 integers per line, a, B. Indicates that course a is a pre-set course for Course B.

Output

1th.. T line: 1 strings per line, if the group information is correct, output "Correct", if the group information is wrong, output "wrong".

Sample input
22 21 22 13 21 21 3
Sample output
Wrongcorrect

Of course, the topology is very good to think, the degree of 0 of a minus, minus the neighboring degrees minus one.

Try to use the ring of thought to do, incredibly WA, black face

#include <cstdio>#include<cstdlib>#include<cstring>#include<iostream>using namespacestd;Const intmaxn=3000010;intlaxt[maxn],next[maxn],to[maxn],cnt;intRU[MAXN],VIS[MAXN];BOOLFlag;voidAddintUintv) {next[++cnt]=Laxt[u]; Laxt[u]=CNT; TO[CNT]=v;}voidDfsintUintFA) {Vis[u]=FA;  for(intI=laxt[u];i;i=Next[i]) {         if(!Vis[to[i]]) DFS (TO[I],FA); Else if(vis[to[i]]==FA) {Flag=false; return ; }    }}intMain () {inti,n,j,t,m,u,v; scanf ("%d",&T);  while(t--) {flag=true; memset (Laxt,0,sizeof(LAXT)); memset (Ru,0,sizeof(RU)); memset (Vis,0,sizeof(VIS)); CNT=0; scanf ("%d%d",&n,&m);  for(i=1; i<=m;i++) {scanf ("%d%d",&u,&v);            Add (U,V); RU[V]++; }         for(i=1; i<=n;i++){            if(!Ru[i]) DFS (i,i); }         for(i=1; i<=n;i++)            if(!Vis[i]) flag=false; if(flag) printf ("correct\n"); Elseprintf"wrong\n"); }    return 0;}

Hihocoder 1174 topology Sequencing • One

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.