Zju1015 Fishing Net

  弦图判定

  代码

 1 #include<cstdio>
 2 #include<queue>
 3 #define mp make_pair
 4 #define fi first
 5 #define sc second
 6 using namespace std;
 7 const int N = 2001010;
 8 int n,m,a,b,i,j;
 9 int dp,p[N],pre[N],tt[N],o,vis[N],sum[N],id[N],ID[N];
10 priority_queue<pair<int,int> > Q;
11 void link(int x,int y)
12 {
13     dp++;pre[dp]=p[x];p[x]=dp;tt[dp]=y;
14 }
15 int main()
16 {
17     scanf("%d%d",&n,&m);
18     for (i=1;i<=m;i++)
19     {
20         scanf("%d%d",&a,&b);
21         link(a,b);
22         link(b,a);
23     }
24     for (i=1;i<=n;i++)
25     Q.push(mp(0,i));
26     o=n;
27     while (!Q.empty())
28     {
29         int x=Q.top().fi;
30         int y=Q.top().sc;
31         Q.pop();
32         if (vis[y]) continue;
33         if (x<sum[y]) continue;
34         ID[y]=o;
35         id[o--]=y;
36         vis[y]=1;
37         i=p[y];
38         while (i)
39         {
40             if (!vis[tt[i]])
41             {
42                 sum[tt[i]]++;
43                 Q.push(mp(sum[tt[i]],tt[i]));
44             }
45             i=pre[i];
46         }
47     }
48     for (i=1;i<=n;i++) vis[i]=0;
49
50     for (j=1;j<=n;j++)
51     {
52         int x=id[j],cnt1=0,cnt2=0,mi=0x37373737,y=0;
53         i=p[x];
54         while (i)
55         {
56             if (ID[tt[i]]>j)
57             {
58                 if (ID[tt[i]]<mi) mi=ID[tt[i]],y=tt[i];
59                 vis[tt[i]]=1;cnt1++;
60             }
61             i=pre[i];
62         }
63
64         if (y)
65         {
66             i=p[y];
67             while (i)
68             {
69                 if (vis[tt[i]]) cnt2++;
70                 i=pre[i];
71             }
72         }
73         if ((cnt1!=cnt2+1)&&(y))
74         {
75             printf("Imperfect");
76             return 0;
77         }
78         i=p[x];
79         while (i)
80         {
81             vis[tt[i]]=0;
82             i=pre[i];
83         }
84     }
85     printf("Perfect");
86 }
时间: 2024-08-29 13:22:07

Zju1015 Fishing Net的相关文章

bzoj 1242: Zju1015 Fishing Net 弦图判定

1242: Zju1015 Fishing Net弦图判定 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 214  Solved: 81[Submit][Status][Discuss] Description 在 一个高度信息化的渔村,鱼网的制作和修补都是由电脑完成.众所周知,鱼网是由网组成的(废话),网组成的东西叫网眼.如果网眼够小,就能捕到很多鱼:如果 网眼太大,鱼就会全部漏走.每次捕鱼回来,鱼网都会烂得很厉害,小网眼会变成网眼,那鱼网就需

[ZOJ 1015]Fishing Net(MCS弦图的判定)

Description 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

uva 757 Gone Fishing (贪心)

uva 757 Gone Fishing John is going on a fishing trip. He has h hours available ( ), and there are n lakes in the area ( ) all reachable along a single, one-way road. John starts at lake 1, but he can finish at any lake he wants. He can only travel fr

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

Gone Fishing Time Limit: 2000MS   Memory Limit: 32768K Total Submissions: 30281   Accepted: 9124 Description John is going on a fishing trip. He has h hours available (1 <= h <= 16), and there are n lakes in the area (2 <= n <= 25) all reachab

贪心算法 -- gone fishing

poj 1042 gone fishing 题目要求: 由有n个湖, 按照顺序排列,一个人从第一个湖向最后一个湖行进(方向只能从湖0到湖n-1),途中可以在湖中钓鱼.在每个湖中钓鱼时,开始的5分钟内可以钓到 f[i] 条,之后每5分钟钓到的鱼数目递减 d[i] ,且每两个相邻的湖的距离 t[i] 给出(t[i] 表示 由第 i 个湖向第 i + 1个湖行进在路上花费5分钟的倍数的时间, 即如果t[3] = 4,则表示从第三个湖向第四个湖行进需要花费20分钟). 现给定总时间h 小时,求出在每个湖

ZOJ 1015 Fishing Net(判断弦图)

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=15 题意:给定一个图.判断是不是弦图? 思路:(1)神马是弦图?对于一个无向图,若该图的任意一个长度大于3的环中存在一条边连接这个环上不相邻的两点,则此图称作弦图. (2)什么是团?团是原图的一个子图,子图就是包含了原图的某些点,那么就要包含这些点之间的边.并且团不是一般的子图而是一个完全子图,就是这个子图的任意两个顶点之间都有边.下面的ABCD就是原图的一个团. (

ZOJ 1015 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

uva757 - Gone Fishing(贪心)

题目:uva757 - Gone Fishing(贪心) 题目大意:有N个湖泊只有一条通路将这些湖泊相连.每个湖泊都会给最开始5分钟间隔内可以调到的鱼(f),然后给每过5分钟减少的鱼的数量(d),如果当前的鱼少于等于减少的数量,说明在下个5分钟没有鱼.还有过每条道路的所要耗费的时间(N-1),时间都是以5分钟为单位的.渔者可以在任意一个湖泊钓鱼,但是起始位置是在湖泊1.问H小时后,渔者怎样合理的在每个湖泊分配时间,可以得到的鱼最多.如果得到最多的鱼的方式有多种,则取在前面的湖泊耗时最久的那一种.

POJ-1042 Gone Fishing (贪心法求最佳钓鱼方案

Gone Fishing Time Limit: 2000MS   Memory Limit: 32768K Total Submissions: 28075   Accepted: 8371 Description John is going on a fishing trip. He has h hours available (1 <= h <= 16), and there are n lakes in the area (2 <= n <= 25) all reachab