Noj 2015 Shaanxi Province Program Design Competition Network preliminary (official race) (busy course selection system-topological sort note heavy side)

Source: Internet
Author: User

D-Busy Course selection system time Limit:10000Ms Memory Limit:65536Kbsubmitdescription

At the end of each semester, are the most attention to the course of choice, due to the number of people, a school server is often crowded with countless students to explode, this is, the educational system adults said, you choose a class is so slow, incredibly still blame us. So every time the administration system shuts down the server before it gets paralyzed. In the fierce protests of countless students, the academic system compromised and gave everyone a chance, but he asked us to decide the course in the quickest way and then quit when we chose.

This makes the freshman dog difficult, under the new elective system, each student can choose a freshman to a senior to any course, or even not their own professional classes. However, this will lead to a lot of new problems, if I before the higher mathematics, I took the circuit analysis basis, then the slag will hang branch, but no one want to hang section.

The school will have to take at least N courses next semester, otherwise, the dregs won't be able to study normally.

Suppose the school in each class after the completion of another course, the dregs want to know if he will hang the next semester. It is assumed that the slag will not hang in the normal order of subjects.

Slag again puzzled, can only ask genius, the result, Ganxiu genius looked at a glance after the conclusion, is worthy of genius.

Genius Special Love show, after glancing at it,

If the slag hangs up, he will say: "You'll fail some exam, but I think I can deal with it."

If the slag does not hang and there is only one course arrangement, he will say, "I ve got it by using my IQ and RP."

If there are multiple arrangements, genius will say: "It's Too easy." I ' ve found many solutions in my first glance. "

Input

The input data contains more than one line, the first line gives N,k (0≤n≤1500,2≤k≤1500), the next semester will be the N course, in the next K row, each line has at least two numbers, the first number represents the sequence number of course A (a≤n), followed by each number for B's class number, And only after the course B has finished learning to understand course a, in this k line, each line will end with 0, 0 will not be the course number of any course.

Enter with EOF cutoff.

Output

For each result, output genius will say, if the answer is unique, output this set of answers on the next line.

Sample Input
4 31 2 3 4 02 3 4 03 4 0
Sample Output
I ' ve got it by using my IQ and RP.4 3 2 1
Hint

-

sort topology, pay attention to heavy edges
#include <cstdio> #include <cstring> #include <cstdlib> #include <algorithm> #include < functional> #include <iostream> #include <cmath> #include <cctype> #include <ctime>using namespace std; #define for (I,n) for (int. i=1;i<=n;i++) #define FORK (I,k,n) for (int. i=k;i<=n;i++) #define REP (I,n) for (int i=0;i<n;i++) #define ForD (I,n) for (int. i=n;i;i--) #define REPD (I,n) for (int. i=n;i>=0;i--) #define FORP (x) for ( int p=pre[x];p; p=next[p]) #define FORPITER (x) for (int &p=iter[x];p; p=next[p]) #define LSON (x<<1) #define Rson ((x<<1) +1) #define MEM (a) memset (A,0,sizeof (a)), #define MEMI (a) memset (A,127,sizeof (a)), #define MEMI (a) memset ( A,128,sizeof (a)); #define INF (2139062143) #define F (100000007) #define MAXN (1500+100) typedef long Long Ll;ll Mul (ll A,ll b) {return (a*b)%F;} ll Add (ll A,ll b) {return (a+b)%F;} ll Sub (ll A,ll b) {return (a-b+ (a)/f*f+f)%F; void Upd (ll &a,ll b) {a= (a%f+b%f)%F;} int K;const Char s1[]= "You'll fail some exam, but I Think I can deal with it.\n "; const char s2[]=" I ' ve got it by using my IQ and rp.\n "; const char s3[]=" It's too easy. I ' ve found many solutions in my first glance.\n "; int n,indegree[maxn];int f[maxn][maxn];bool b[maxn];int q[maxn*4];void to        Psort () {int head_=1,tail=0;int fl=0,flm=0;            Fork (I,1,n) if (indegree[i]==0) {q[++tail]=i;b[i]=1; ++fl;        } if (fl>1) flm=1;        while (Head_<=tail) {fl=0;            int Now=q[head_];                    Fork (V,1,n) while (F[now][v]) {indegree[v]--;f[now][v]--;                    if (indegree[v]==0) {q[++tail]=v;b[v]=1; ++fl;            }} head_++;                            if (fl>1) flm=1;         } if (tail==n) {if (FLM) printf ("%s", S3); else {printf ("%s", S2); printf ("%d", q[1]);      Fork (i,2,n) printf ("%d", Q[i]);p rintf ("\ n");        }}else printf ("%s", S1); } int main () {//freopen ("d.in", "R", stdin),//freopen (". Out", "w", stdout) and while (scanf ("%d%d", &n,&k) ==2) {MEM ( f) Mem (Indegree) mem (q) mem (b) for (i,k) {int p,p2;scanf ("%d", &p) and while (scanf ("%d", &AMP;P2) ==1) {if (f[p2][p]) Continue if (P2) F[p2][p]++,indegree[p]++;else break;}} Topsort ();} return 0;}








Noj 2015 Shaanxi Province Program Design Competition Network preliminary (official race) (busy course selection system-topological sort note heavy side)

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.