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

Obviously, the smaller the leaks in the fishing nets are, the more fishes they
will catch. So after coming back, those fishermen will input the information
of the fishing nets into the computer to check whether the nets have leaks.

The checking principle is very simple: The computer regards each fishing net
as a simple graph constructed by nodes and edges. In the graph, if any circle
whose length (the number of edges) is larger than 3 must has at least one chord,
the computer will output "Perfect" indicating that the fishnet has
no leaks. Otherwise, "Imperfect" will be displayed and the computer
will 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 two different nodes on the circle, but it does not belong to the set
of edges on the circle.

Input

The input file contains several test cases representing different fishing nets.
The last test case in the input file is followed by a line containing 0 0.

The first line of each test case contains two integers, n and m, indicating
the number of nodes and edges on the net respectively, 1 <= n <= 1000. It is followed
by m lines accounting for the details of the edges. Each line consists of two
integers xi and yi, indicating there is an edge between node xi and node yi.

Output

For each test case, display its checking results. The word "Imperfect"
suggests that the corresponding fishing net is leaking, while the word "Perfect"
stands for a fishing net in good condition.

Follow the output for each net with a blank line.

Sample Input

4 4
1 2
2 3
3 4
4 1
3 3
1 2
2 3
3 1
0 0

Output for the Sample Input

Imperfect

Perfect

判断是否是弦图。

检查一个图是否是弦图:

设已编号的节点集合为A,未编号的节点集合为B
开始时A为空,B包含所有节点。
for num=n-1 downto 0 do
{
  在B中找节点x,使与x相邻的在A集合中的节点数最多,将x编号为num,
  并从B移入A
}
第二步:检查
for num=0 to n-1 do
{
  对编号为num的节点x,设所有编号大于num且与x相邻的节点集合为C,
  在集合C中找出编号最小的节点y,如果集合C中存在不等于y的节点z,
  且y与z间没有边,则此图不是弦图,退出。
}

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <ctime>
#include <cstdlib>
#include <map>
#include <set>
using namespace std;
#pragma comment(linker, "/stck:1024000000,1024000000")
#define lowbit(x) (x&(-x))
#define max(x,y) (x>=y?x:y)
#define min(x,y) (x<=y?x:y)
#define MAX 100000000000000000
#define MOD 1000
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.1415926535897932384626433832
#define ios() ios::sync_with_stdio(true)
#define INF 1044266558
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
vector<int>a[],pb;
int d[],dis[][],q[],id[],n,m,u,v;
bool vis[];
void init()
{
for(int i=;i<=n;i++)
a[i].clear();
memset(dis,,sizeof(dis));
memset(vis,,sizeof(vis));
memset(d,,sizeof(d));
}
bool mcs_check()
{
for(int i=;i<=n;i++)
{
pb.clear();
for(int j=i+;j<=n;j++)
{
if(dis[q[i]][q[j]]) pb.push_back(q[j]);
}
for(int j=;j<pb.size();j++)
if(!dis[pb[]][pb[j]]) return false;
}
return true;
}
int main()
{
while(scanf("%d%d",&n,&m) && n+m)
{
init();
for(int i=;i<m;i++)
{
scanf("%d%d",&u,&v);
dis[u][v]=dis[v][u]=;
a[u].push_back(v);
a[v].push_back(u);
}
d[]=-;
for(int i=n;i;i--)
{
int x=;
for(int j=;j<=n;j++)
if(!vis[j] && d[j]>d[x]) x=j;
q[i]=x;vis[x]=;id[x]=i;
for(int j=;j<a[x].size();j++)
d[a[x][j]]++;
}
printf("%s\n\n",mcs_check()?"Perfect":"Imperfect");
}
return ;
}

Fishing Net的更多相关文章

  1. ZOJ 1015 Fishing Net(弦图判定)

    In a highly modernized fishing village, inhabitants there make a living on fishery. Their major tool ...

  2. bzoj 1242: Zju1015 Fishing Net 弦图判定

    1242: Zju1015 Fishing Net弦图判定 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 214  Solved: 81[Submit ...

  3. Poj/OpenJudge 1042 Gone Fishing

    1.链接地址: http://bailian.openjudge.cn/practice/1042/ http://poj.org/problem?id=1042 2.题目: Gone Fishing ...

  4. POJ 1042 Gone Fishing (贪心)(刘汝佳黑书)

    Gone Fishing Time Limit: 2000MS   Memory Limit: 32768K Total Submissions: 30281   Accepted: 9124 Des ...

  5. uva757 - Gone Fishing(馋)

    题目:uva757 - Gone Fishing(贪心) 题目大意:有N个湖泊仅仅有一条通路将这些湖泊相连. 每一个湖泊都会给最開始5分钟间隔内能够调到的鱼(f).然后给每过5分钟降低的鱼的数量(d) ...

  6. ●BZOJ 1006 [HNOI2008]神奇的国度(弦图最小染色数)○ZOJ 1015 Fishing Net

    ●赘述题目 给出一张弦图,求其最小染色数. ●题解 网上的唯一“文献”:<弦图与区间图>(cdq),可以学习学习.(有的看不懂) 摘录几个解决改题所需的知识点: ●子图和诱导子图(一定要弄 ...

  7. Cocos2d-X开发教程-捕鱼达人 Cocos2-x development tutorial - fishing talent

    Cocos2d-X开发教程-捕鱼达人 Cocos2-x development tutorial - fishing talent 作者:韩梦飞沙 Author:han_meng_fei_sha 邮箱 ...

  8. CSU 1859 Gone Fishing(贪心)

    Gone Fishing [题目链接]Gone Fishing [题目类型]贪心 &题解: 这题要先想到枚举走过的湖,之后才可以贪心,我就没想到这,就不知道怎么贪心 = = 之后在枚举每个湖的 ...

  9. Gone Fishing(贪心)

    Gone Fishing John is going on a fising trip. He has h hours available (1 ≤ h ≤ 16), and there are n ...

  10. LightOJ1106 Gone Fishing

    Gone Fishing John is going on a fishing trip. He has h hours available, and there are n lakes in the ...

随机推荐

  1. MarkDown写作之嵌入LaTeX和HTML

    本系列文章由 @YhL_Leo 出品,转载请注明出处. 文章链接: http://blog.csdn.net/yhl_leo/article/details/49788741 Markdown 是一种 ...

  2. PNG文件结构分析

    http://blog.163.com/iwait2012@126/blog/static/16947232820124411174877/ PNG文件结构分析 对于一个PNG文件来说,其文件头总是由 ...

  3. ASP.NET-文件上传代码

    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 3 ...

  4. dll签名两种方法

    以下两种签名方法,都是对csp.dll签名,都不是CA颁发的,且效果不同, 一:通过自建证书签名 下载windows sdk,成功安装后,包括makecert.exe, cert2spc.exe, p ...

  5. 从头认识java-17.2 线程中断(interrupt)

    这一章节我们来讨论一下线程中断(interrupt). 1.什么是线程中断(interrupt)? 就是在多线程执行的时候,我们给线程贴上一个中断的标记.可是不要求线程终止. 2.样例: 中断的样例: ...

  6. UNIX环境高级编程之第4章:文件和文件夹-习题

    4.1 stat函数是尾随符号链接的,所以用stat替换lstat不会显示符号链接的信息 4.2 在一个目录下先再shell中输入umask shell进程再进行创建文件的操作.其权限抖都会被屏蔽 4 ...

  7. How to Download Windows 10 Spotlight/Lock Screen Images

    http://www.online-tech-tips.com/windows-10/download-windows-10-spotlight-lock-screen-images/ 图片位置 C: ...

  8. Android RecyclerView 水平滚动+自动循环轮播

    主要处理的地方: 1.RecyclerView中Adapter的item个人可以无限轮询. 2.RecyclerView自动滑动 3.手指按下时滑动停止,手指抬起后继续自动滑动 public clas ...

  9. ui5 call view or method from another view

    // call view or method from another view //# view call // var view2=sap.ui.jsview("ui5d.popup01 ...

  10. vue中Object.defineProperty用法

    function def (obj, key, val, enumerable) { Object.defineProperty(obj, key, { value: val, enumerable: ...