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. Json学习总结(2)——Java 下的 JSON库性能比较:JSON.simple vs. GSON vs. Jackson vs. JSONP

    JSON已经成为当前服务器与WEB应用之间数据传输的公认标准,不过正如许多我们所习以为常的事情一样,你会觉得这是理所当然的便不再深入思考了.我们很少会去想用到的这些JSON库到底有什么不同,但事实上它 ...

  2. ios开发经常使用到的第三方库

    由于iOS SDK相对照较底层,所以开发人员就得受累多做一些体力活.只是幸运的是,有非常多第三方的类库能够用来简化非常多不必要的工作.经过作者团队的谨慎讨论.他们 评选出了10款可以极大提高iOS开发 ...

  3. [Mobx] Using mobx to isolate a React component state

    React is great for diffing between Virtual-DOM and rendering it to the dom. It also offers a naïve s ...

  4. 如何将visual studio 2010编辑模式改为插入???

    按一下键盘上的 insert button 反之亦然

  5. QtWebkit里RenderLayer树的绘制具体流程分析

           更新:RenderLayer树的绘制对RenderObject的绘制.同一时候补足绘制阶段的描写叙述.        QtWebkit里,QWebView,QWebPage和QWebFr ...

  6. hdu_1166,线段树单点更新

    在刷线段树,参考自http://www.notonlysuccess.com/index.php/segment-tree-complete/ #include<iostream> #in ...

  7. PHP join() 函数

    PHP join() 函数 实例 把数组元素组合为一个字符串: <?php $arr = array('Hello','World!','I','love','Shanghai!'); echo ...

  8. [HNOI2012] 永无乡 解题报告 (splay+启发式合并)

    题目链接:https://www.luogu.org/problemnew/show/P3224#sub 题目: 题目大意: 维护多个联通块,没有删除操作,每次询问某一联通块的第k大 解法: 维护联通 ...

  9. CUDA笔记(七)

    今天集中时间找程序的问题.于是发现: 首先,程序里的kernel想要调试,必须用nsight. 于是一堆找.http://www.nvidia.com/object/nsight.html http: ...

  10. sql索引碎片产生的原理 解决碎片的办法(sql碎片整理)

    本文讲述了SQL SERVER中碎片产生的原理,内部碎片和外部碎片的概念.以及解决碎片的办法和填充因子.在数据库中,往往每一个对于某一方面性能增加的功能也会伴随着另一方面性能的减弱.系统的学习数据库知 ...