Light OJ 1201 - A Perfect Murder
来源:互联网 发布:c语言写俄罗斯方块 编辑:程序博客网 时间:2024/05/18 00:23
"Yes, I am the murderer. No doubt" I had to confess it in front of all. But wait, why I am confessing? Nobody wants to go to jail, neither do I. As you have suspected there is something fishy. So, let me explain a bit.
The murder was happened in 19th June, at 11:30 pm this year (2009) according to the medical report. So, I was asking the judge "Can you find the time 19th June 11:30 pm in Bangladesh?" The judge informed other reporters to find the time. But alas! There was no time - "2009, 19th June, 11:30 pm". So, the judge got a bit confused about my confession. So, I began to tell them, "The time the murder was happened, is not a valid time according to you. So, how can you claim that I am the murderer?"
And what happened next, you all know. I am in the streets again with a clean sheet.
But now I have planned to kill again. I have a list of N mosquitoes which are to be killed. But there is a small problem. If I kill a mosquito, all of his friends will be informed, so they will be prepared for my attack, thus they will be impossible to kill. But there is a surprising fact. That is if I denote them as a node and their friendship relations as edges, the graph becomes acyclic.
Now I am planning when and how to kill them (how to get rid of the law!) and you have to write a program that will help me to find the maximum number of mosquito I can kill. Don't worry too much, if anything goes wrong I will not mention your name, trust me!
Input
Input starts with an integer T (≤ 50), denoting the number of test cases.
Each case starts with a blank line and two integers N (1 ≤ N ≤ 1000) denoting the number of mosquito I want to kill and M denoting the number of friendship configurations. Each of the next Mlines contains two integers a and b denoting that ath and bth mosquitoes are friends. You can assume that (1 ≤ a, b ≤ N, a ≠ b) and each friendship relation is given only once. As I have already mentioned, you will not find any cycle in the relations.
Output
For each case, print the case number and the maximum number of mosquitoes I can kill considering the conditions described above.
Sample Input
Output for Sample Input
3
4 3
1 2
1 3
1 4
3 2
1 2
2 3
5 4
1 2
1 3
2 4
2 5
Case 1: 3
Case 2: 2
Case 3: 3
代码:
#include<cstdio>#include<cstring>bool map[1020][1020];bool fafe[1010]; int shu[1010];int main(){int t;scanf("%d",&t);for (int ca=1;ca<=t;ca++){int n,m;scanf("%d%d",&n,&m);memset(map,false,sizeof(map));memset(fafe,true,sizeof(fafe));memset(shu,0,sizeof(shu));int a,b;for (int i=0;i<m;i++){scanf("%d%d",&a,&b);shu[a]++;shu[b]++;map[a][b]=map[b][a]=true;}int s=0;while (1){bool lp=false;int ii,mi=100000;for (int i=1;i<=n;i++)if (fafe[i]&&shu[i]<mi){lp=true;ii=i;mi=shu[i];}if (lp==false)break;s++;fafe[ii]=false;for (int i=1;i<=n;i++)if (fafe[i]&&map[i][ii]){fafe[i]=false;for (int j=1;j<=n;j++)if (fafe[j]&&map[i][j])shu[j]--;}}printf("Case %d: %d\n",ca,s);}return 0;}
- Light OJ 1201 - A Perfect Murder
- Light oj 1201 - A Perfect Murder(树形dp)
- Light OJ 1201 A Perfecr Murder (简单树形DP)
- LightOJ - 1201 A Perfect Murder(树形DP)
- lightoj 1201 - A Perfect Murder 树形DP
- LightOJ 1201 - A Perfect Murder【二分图最大独立集】
- LightOJ 1201 A Perfect Murder 最大独立集
- LOJ 1201 - A Perfect Murder(二分匹配 最大独立集)
- Light OJ 1170 Counting Perfect BST (DP+数学)
- Light OJ 1036A Refining Company (DP)
- Light OJ 1006 Hex-a-bonacci
- Light OJ 1277 Looking for a Subsequence
- light oj 1020 - A Childhood Game (博弈)
- Light OJ 1036A Refining Company
- light oj 1220 Fantasy of a Summation
- Light OJ 1288 Subsets Forming Perfect Squares 高斯消元求矩阵的秩
- light oj
- light oj
- Android Native进程内存泄露检测
- Android手机 Fildder真机抓包
- Android解决ViewPager页面滑动空白bug和图片点击bug
- Activity的环型跳转问题
- Tomcat启动完成后再执行一个指定的方法 - 不影响Tomcat的启动时间
- Light OJ 1201 - A Perfect Murder
- 强大和简单的顶部导航栏效果
- VS与SQL Server连接时出现(provider: TCP Provider, error: 0)错误时的解决方法
- 2016精选通用Java面试题二
- 在ListView里面去添加跑马灯的效果
- intellij idea 2016破解
- 合肥,雨;午,未眠(自学之殇)
- onerror事件用法
- 错误记录:由于目标计算机积极拒绝,无法连接。 127.0.0.1:49681