ZOJ 1015 Fishing Net (chord chart Determination)

Source: Internet
Author: User

Http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=15

Test instructions

Determine if the string is a chord chart.

Ideas:

The so-called string graph, that is, for an no-map, if any one of the length of the graph is greater than 3 of the ring has an edge connected to the ring is not adjacent to the two points, then this graph is called the chord graph.

The judgement of the string figure is not difficult, first use the most popular algorithm to calculate the perfect elimination sequence, and then use the perfect elimination sequence to determine whether the original image is a string graph, how to judge the original image from the perfect elimination sequence is not a chord chart? The simplest way is to determine, in turn, whether all the points adjacent to VI in the {vi+1,..., vn} constitute a regiment. This can be optimized by setting {vi+1,..., vn} where all the points adjacent to VI are VJ1,......, VJK. Simply determine if the vj1 is adjacent to the Vj2,......, vjk.

1#include <iostream>2#include <algorithm>3#include <cstring>4#include <cstdio>5#include <sstream>6#include <vector>7#include <stack>8#include <queue>9#include <cmath>Ten#include <map> One#include <Set> A using namespacestd; -typedefLong Longll; -typedef pair<int,ll>PLL; the Const intINF =0x3f3f3f3f; - Const intmaxn= ++5; -  - intN, M; + inttot; - intHEAD[MAXN]; + intLABEL[MAXN];//Label[i] indicates that the first point is adjacent to how many labeled points, and each time you select Label[i] the largest non-labeled point to label A intVIS[MAXN]; at intQ[MAXN]; - intMP[MAXN][MAXN]; -  - structnode - { -     intv; in     intNext; -}e[maxn*maxn+5]; to  + voidAddedge (intUintv) - { thee[tot].v=v; *e[tot].next=Head[u]; $head[u]=tot++;Panax Notoginseng } -  the voidMCS ()//Maximum potential algorithm + { Amemset (Vis,0,sizeof(Vis)); thememset (Label,0,sizeof(label)); +      for(inti=n;i;i--) -     { $         intpos=0; $          for(intj=1; j<=n;j++)//Select a value that is not currently accessed and has the largest label -             if(!vis[j] && Label[j]>=label[pos]) pos=J; -vis[pos]=1; theq[i]=Pos; -          for(intj=head[pos];j!=-1; j=e[j].next)//node adjacent to POS node label value +1Wuyilabel[e[j].v]++; the     } - } Wu  - BOOLCheck () About { $      for(intI=1; i<=n;i++) -     { -vector<int>v; -          for(intj=i+1; j<=n;j++) A             if(mp[q[i]][q[j]]==1) V.push_back (Q[j]); +          for(intj=1; J<v.size (); j + +) the             if(mp[v[0]][v[j]]==0)return false; -     } $     return true; the } the  the intMain () the { -     //freopen ("In.txt", "R", stdin); in      while(SCANF ("%d%d", &n,&m)! =EOF) the     { the         if(n==0&& m==0) Break; Abouttot=0; thememset (head,-1,sizeof(head)); theMemset (MP,0,sizeof(MP)); the          while(m--) +         { -             intu,v; thescanf"%d%d",&u,&v);Bayi Addedge (u,v); the Addedge (v,u); themp[u][v]=mp[v][u]=1; -         } - MCS (); the         if(check () = =true) puts ("perfect\n"); the         ElsePuts"imperfect\n"); the     } the     return 0; -}

ZOJ 1015 Fishing Net (chord chart Determination)

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.