[ZOJ 1015] Fishing Net (the determination of MCs chord graphs)

Source: Internet
Author: User
Tags nets

Description

In a highly modernized fishing village, inhabitants there make a living on fishery. Their major tools, fishing nets, is produced and fixed by computer. After catching fishes all time, together with plenty of fishes, they would bring back the shabby fishing nets, which might be full of leaks. Then they has to inspect those nets. If there exist large leaks, they has to repair them before launching out again.

Obviously, the smaller the leaks in the fishing nets is, the more fishes they would catch. So after coming back, those fishermen would input the information of the fishing nets into the computer to check whether th E nets has leaks.

The checking principle is very simple:the computer regards each fishing net as a simple graph constructed by nodes and Ed Ges. In the graph, if any circle whose length (the number of edges) is larger than 3 must have at least one chord, the computer Would output "Perfect" indicating that the fishnet have no leaks. Otherwise, "Imperfect" would be displayed and the computer would try to repair the net.

Note:a Circle is A closed loop, which starts from one node, passes through other distinct nodes and back to the starting Node. A chord is an edge, which connects and different nodes on the circle, but it does isn't belong to the set of edges on the CI Rcle.

Solution

Pe*1 QVQ

Follow the output for each net with a blank line.

the CDQ of chord and interval map

Maximum potential algorithm Maximum cardinality Search

from N to 1 of the order of the point, set label[i] means I and how many labeled points are connected, each time the selection of Label[i] the largest non-marking point label

Determine if the sequence is perfect for elimination

set {vi+1,..., vn} All the points adjacent to VI are VJ1,..., VJK. Simply determine if the vj1 is adjacent to the Vj2,..., vjk.

#include <iostream>#include<cstdio>#include<cstring>#include<cstdlib>#defineMAXN 1005using namespacestd;intN,M,MAP[MAXN][MAXN],LABEL[MAXN],NUM[MAXN],VISITED[MAXN];voidWork () { for(intI=n;i>0; i--)    {        intu=0;  for(intj=1; j<=n;j++)        if(!u| | (!visited[j]&&label[j]>label[u])) u=J; Visited[u]=1; num[i]=u;  for(intj=1; j<=n;j++)        {            if(map[u][j]&&!Visited[j]) label[j]++; }    }}BOOLjudge () { for(intI=1; i<n;i++)    {        intt=i+1;  while(t<=n&&! Map[num[i]][num[t]]) t++;  for(intj=t+1; j<=n;j++)        {            if(map[num[i]][num[j]]&&!Map[num[t]][num[j]])return false; }    }    return true;}intMain () { while(~SCANF ("%d%d", &n,&m) &&N) {memset (Map,0,sizeof(MAP)); memset (Label,0,sizeof(label)); Memset (visited,0,sizeof(visited)); intu,v;  for(intI=1; i<=m;i++) {scanf ("%d%d",&u,&v); MAP[U][V]=map[v][u]=1;        } work (); if(judge ()) printf ("perfect\n"); Elseprintf"imperfect\n"); printf ("\ n"); }    return 0;}

[ZOJ 1015] Fishing Net (the determination of MCs chord graphs)

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.