Fishing Net
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的更多相关文章
- ZOJ 1015 Fishing Net(弦图判定)
In a highly modernized fishing village, inhabitants there make a living on fishery. Their major tool ...
- bzoj 1242: Zju1015 Fishing Net 弦图判定
1242: Zju1015 Fishing Net弦图判定 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 214 Solved: 81[Submit ...
- Poj/OpenJudge 1042 Gone Fishing
1.链接地址: http://bailian.openjudge.cn/practice/1042/ http://poj.org/problem?id=1042 2.题目: Gone Fishing ...
- POJ 1042 Gone Fishing (贪心)(刘汝佳黑书)
Gone Fishing Time Limit: 2000MS Memory Limit: 32768K Total Submissions: 30281 Accepted: 9124 Des ...
- uva757 - Gone Fishing(馋)
题目:uva757 - Gone Fishing(贪心) 题目大意:有N个湖泊仅仅有一条通路将这些湖泊相连. 每一个湖泊都会给最開始5分钟间隔内能够调到的鱼(f).然后给每过5分钟降低的鱼的数量(d) ...
- ●BZOJ 1006 [HNOI2008]神奇的国度(弦图最小染色数)○ZOJ 1015 Fishing Net
●赘述题目 给出一张弦图,求其最小染色数. ●题解 网上的唯一“文献”:<弦图与区间图>(cdq),可以学习学习.(有的看不懂) 摘录几个解决改题所需的知识点: ●子图和诱导子图(一定要弄 ...
- Cocos2d-X开发教程-捕鱼达人 Cocos2-x development tutorial - fishing talent
Cocos2d-X开发教程-捕鱼达人 Cocos2-x development tutorial - fishing talent 作者:韩梦飞沙 Author:han_meng_fei_sha 邮箱 ...
- CSU 1859 Gone Fishing(贪心)
Gone Fishing [题目链接]Gone Fishing [题目类型]贪心 &题解: 这题要先想到枚举走过的湖,之后才可以贪心,我就没想到这,就不知道怎么贪心 = = 之后在枚举每个湖的 ...
- Gone Fishing(贪心)
Gone Fishing John is going on a fising trip. He has h hours available (1 ≤ h ≤ 16), and there are n ...
- LightOJ1106 Gone Fishing
Gone Fishing John is going on a fishing trip. He has h hours available, and there are n lakes in the ...
随机推荐
- Qt5的插件机制(1)--Qt 框架中的插件载入机制概述
概述 Qt的源代码中通过 Q<pluginType>Factory.Q<pluginType>Plugin 和 Q<pluginType> 这三个类实现了Qt的插件 ...
- 4、java变量、函数、基本类型的值传递、分支、循环、流程控制
一.全局变量(global).局部变量(local).动态变量(dynamic).静态变量(static) 在类中的变量为全局变量,在方法函数中为局部变量,局部变量必须有人为赋的初值,全局变量的初值是 ...
- mysql-联结
一.联结 联结是利用SQL的select能执行的最重要的操作. 1.关系表:假如有一个包含产品目录的数据库表,其中每个类别的物品占一行.对于每种物品要求存储的信息包括产品描述和价格,以及生产该产品的供 ...
- hdu 2037 贪心
今年暑假不AC Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Su ...
- HDU 3652 B-number(数位dp&记忆化搜索)
题目链接:[kuangbin带你飞]专题十五 数位DP G - B-number 题意 求1-n的范围里含有13且能被13整除的数字的个数. 思路 首先,了解这样一个式子:a%m == ((b%m)* ...
- 自己封装js组件 - 中级
书接上文,上次弄了个基本版本的alert组件(其实就是十分钟前)但是很多功能都没有实现 没有关闭按钮 没有下面确定按钮 没有模态框 没有这那的 这次终极篇就都给它完善好弄个中级版本也是基本可用版本! ...
- 双系统给ubuntu增加分区
http://www.th7.cn/system/lin/201506/106338.shtml http://www.linuxidc.com/Linux/2012-06/61983.htm 因为本 ...
- nyoj--218--Dinner(语法)
Dinner 时间限制:100 ms | 内存限制:65535 KB 难度:1 描述 Little A is one member of ACM team. He had just won the ...
- Windows下VS2013+Caffe无GPU配置
Windows版本的caffe工具包下载地址: 点击打开链接 1. 将下载的caffe-master.zip解压到 D:\Software\Caffe 文件夹下,把 D:\Software\Caffe ...
- P3227 [HNOI2013]切糕
题目描述 经过千辛万苦小 A 得到了一块切糕,切糕的形状是长方体,小 A 打算拦腰将切糕切成两半分给小 B.出于美观考虑,小 A 希望切面能尽量光滑且和谐.于是她找到你,希望你能帮她找出最好的切割方案 ...