Bzoj 1242:zju1015 Fishing Net Chord Graph Judging

Source: Internet
Author: User
Tags nets

1242:zju1015 Fishing Net Chord chart determination time limit:10 Sec Memory limit:162 MB
submit:214 solved:81
[Submit] [Status] [Discuss] Description

In a highly informative fishing village, the production and repair of fish nets are done by computers. As we all know, the net is made up of nets (nonsense), the net is composed of something called mesh. If the mesh is small enough, you can catch a lot of fish; if the mesh is too large, the fish will leak away. Every time fishing back, the nets will be rotten very bad, small mesh will become mesh, the fish network needs to be repaired. They want a program that will tell them if the nets need repairing. The program will look at the fishnet as a map (no further explanation). Their way of judging is that any one length (the number of sides that make up it) has a closed circle of more than 3 and must have a cross line to divide it into two parts. (Hint: recursion down, in fact, every mesh can only be a triangle) if it meets the requirements, the program will output "Perfect", otherwise output "imperfect". Note: The intersection here refers to a junction of a closed loop of the different nodes and catch belong to the side of the ring.

Input

The data begins with a row of N m, indicating that the fishnet has n nodes and M edges. (n<=0<=1000) The following M-line is a description of the M-bar. Two integers per line A, a, a, indicates that there is an edge between Node A and node B.

Output

Output test results for each fishnet, perfect or imperfect

Sample Input4 4
1 2
2 3
3 4
4 1

Sample OutputImperfectHintsource

Chord Chart Determination

The string graph bare topic, is the edge of the range is n^2, not n ...

#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<queue>#include<vector>#include<Set>using namespacestd;#defineMAXN 1010#defineMaxe maxn*maxn*2#defineMAXV MAXNstructedge{intNP; Edge*Next;} E[maxe],*V[MAXV];inttope=-1;voidAddedge (intXinty) {e[++tope].np=y; E[tope].next=V[x]; V[X]=&e[tope];}BOOLVIS[MAXN];intDEG[MAXN];p riority_queue<pair<int,int> >Pq;vector<int>seq;intRK[MAXN];Set<pair<int,int> >S;intMain () {Freopen ("Input.txt","R", stdin); intn,m; scanf ("%d%d",&n,&m); intx, y;  for(intI=0; i<m;i++) {scanf ("%d%d",&x,&y); if(S.find (Make_pair (x, y))!=s.end ())Continue;                Addedge (x, y);                Addedge (Y,X);                S.insert (Make_pair (x, y));        S.insert (Make_pair (y,x)); } pq.push (Make_pair (0,1));  while(!Pq.empty ()) {Edge*NE; Pair<int,int> pr=Pq.top ();                Pq.pop (); if(Vis[pr.second] | | deg[pr.second]!=pr.first)Continue;                Seq.push_back (Pr.second); Vis[pr.second]=true;  for(ne=v[pr.second];ne;ne=ne->next) {                        if(!vis[ne->NP]) {Deg[ne->np]++; Pq.push (Make_pair (Deg[ne->np],ne->np)); }                }        }        if(Seq.size ()! =N) {//printf ("imperfect\n");//return 0;        }         for(intI=0; I<seq.size ()/2; i++) Swap (seq[i],seq[seq.size ()-1-i]);  for(intI=0; I<seq.size (); i++) Rk[seq[i]]=i; Vector<int>VEC;  for(intI=0; I<seq.size (); i++)        {                intnow=Seq[i]; Edge*NE;                Vec.clear ();  for(ne=v[now];ne;ne=ne->next) {                        if(rk[ne->np]>Rk[now]) {Vec.push_back (Rk[ne-NP]);                }} sort (Vec.begin (), Vec.end ());  for(intI=0; I<vec.size (); i++) Vec[i]=Seq[vec[i]];  for(intI=1; I<vec.size (); i++)                {                        if(S.find (Make_pair (vec[0],vec[i]) = =S.end ()) {printf ("imperfect\n"); return 0; }}} printf ("perfect\n");}

Bzoj 1242:zju1015 Fishing Net Chord Graph Judging

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.