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. 紫书 习题 8-16 UVa 1618 (中途相遇法)

    暴力n的四次方, 然而可以用中途相遇法的思想, 分左边两个数和右边两个数来判断, 最后合起来判断. 一边是n平方logn, 合起来是n平方logn(枚举n平方, 二分logn) (1)两种比较方式是相 ...

  2. Myeclipse学习总结(8)——Eclipse实用操作

    工欲善其事,必先利其器.对于程序员来说,Eclipse便是其中的一个"器".本文会从Eclipse快捷键和实用技巧这两个篇章展开介绍.Eclipse快捷键用熟后,不用鼠标,便可进行 ...

  3. CAS-ERR Cannot create a session after the response has been committed

    现象: 当cas 登录人数较少时候没有错误,但是用户过多时候出现下列err May-2016 18:09:11.932 SEVERE [http-nio-8080-exec-52] org.apach ...

  4. Samurai&#39;s Stroke

    题目链接 题意: 一个长度为L的木棍,有n个支点支撑,每一个点是一个int数.表示距离木棍左端点的距离.求在那些位置将木棍劈开能够使得至少有一个木棍掉下去,输出这些位置的长度 3 ≤ l ≤ 109; ...

  5. 在swt中获取jar包中的文件 uri is not hierarchical

    uri is not hierarchical 学习了:http://blog.csdn.net/zdsdiablo/article/details/1519719 在swt中获取jar包中的文件: ...

  6. arcmap 设置线段的不同颜色(及其它转化)

    一: shp 转化为 mxd或导出地图  当时做的第一个shp文件,应该是研一的第二个学期了,都不记得是怎么操作的了. 通过file另存为mxd就可以生成各个shp的arcmap能够直接打开的mxd文 ...

  7. 一步一步跟我学习lucene(19)---lucene增量更新和NRT(near-real-time)Query近实时查询

    这两天加班,不能兼顾博客的更新.请大家见谅. 有时候我们创建完索引之后,数据源可能有更新的内容.而我们又想像数据库那样能直接体如今查询中.这里就是我们所说的增量索引.对于这种需求我们怎么来实现呢?lu ...

  8. magnify.m —— 图像局部放大镜工具函数

    magnify.m 函数下载地址:magnify - File Exchange - MATLAB Central: magnify.m 函数在执行时,是一种交互式处理. 简单演示如下: clear, ...

  9. linux 常用文本操作相关命令

    平时工作经常会对文本进行相关操作,包括读写.替换.统计等等,借此整理和学习一下有关命令. 1. cat 查看文件中的内容, -n 查看时为每一行加编号; -b 和-n类似,只不过对于空白行不编号: 2 ...

  10. 消除textarea的空格de长度值

    在项目中因为用到文本域textarea输入textarea的长度总是显示 25 那是还怀疑textarea自带有value长度? placeholder属性的长度? 那时候想到类似:ul无序列表li元 ...