The method of judging Zoj 1015 fishing Net of chord graph _c language

Source: Internet
Author: User
The idea of doing a problem
1 chord chart, watched a weekend have wood there! Too weak, the algorithm perfectly eliminates the sequence according to the maximum potential algorithm (MCS) given by CDQ's ppt. After the Sumbit 19 times, for WA provides a lot of denominator ah .... Write more points for yourself to back up it.
2 Useful information:
3 theorem: A graph is a chord image if and only if it has a perfect elimination sequence. So first get the perfect elimination sequence:


4 How to determine if you are getting the perfect elimination sequence:


Paste code: (v*v complexity ... )

Copy Code code as follows:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace Std;
const int MAXN=1000+10;
int GRA[MAXN][MAXN];
int n, m;
int LABEL[MAXN], TEMP[MAXN], NUM[MAXN];
void Numbervertex ()
{
int I, J;
Label[n]=0, Num[n]=1;
for (i=n; i>=1; i--)
{
int Mm=-1, POS;
For (J=1 j<=n; j + +)
{
if (!num[j] && label[j]>mm)
{
MM=LABEL[J];
Pos=j;
}
}
Num[pos]=i;
For (J=1 j<=n; j + +)
{
if (!num[j] && (gra[pos][j) | | | gra[j][pos])
label[j]++;
}
}
return;
}
int check ()
{
int I, j, Flag=1;
for (I=1; i<=n && flag; i++)
{
memset (temp,0,sizeof (temp));
int len=0;
For (J=1 j<=n; j + +)
{
if (Num[i]<num[j] && gra[I [j])
{
Temp[len++]=j;
}
}
For (J=1 j<len; j + +)//In this WA day there are wood ...
if (num[temp[0]]>num[temp[j])
Swap (temp[0], temp[j]);
For (J=1 j<len; j + +)
if (!gra[temp[0] [temp[j]])
{
flag=0;
Break
}
}
return flag;
}
int main ()
{
while (scanf ("%d%d", &n,&m)!=eof)
{
if (n==0 && m==0)
Break
memset (label,0,sizeof (label));
memset (num,0,sizeof (num));
memset (gra,0,sizeof (GRA));
for (int i=0; i<m; i++)
{
int x, y;
scanf ("%d%d", &x, &y);
Gra[x][y]=gra[y][x]=1;
}
Numbervertex ();
if (check ())
Puts ("perfect\n");
Else
Puts ("imperfect\n");
}
return 0;
}

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.