POJ_3342_Party_at_Hali-Bula
2024-10-19 11:55:29
#include <iostream>
#include <map>
#include <cstring>
using namespace std; int Graph[210][210];
int DP[210][2];
int count; void DFS( int index ){
DP[index][0] = 0;
DP[index][1] = 1;
for( int i = 1; i <= count; ++i ){
if( Graph[index][i] ){
DFS(i);
DP[index][0] += max( DP[i][0], DP[i][1] );
DP[index][1] += DP[i][0];
}
}
} bool check(){
for( int i = 1; i <= count; ++i ){
if( DP[i][0] == DP[i][1] ){
for( int j = 1; j <= count; ++j ){
if( Graph[i][j] == 1 && DP[j][0] == DP[j][1] ) return false;
}
}
}
return true;
} int main(){
while( true ){
memset( Graph, 0, sizeof(Graph) );
count = 1;
map<string, int>mapTemp;
int n;
cin>>n;
if( n == 0 ) break;
string boss;
cin>>boss;
mapTemp[boss] = count++;
for( int i = 2; i <= n; ++i ){
string son;
string parent;
cin>>son>>parent;
if( !mapTemp[son] ) mapTemp[son] = count++;
if( !mapTemp[parent] ) mapTemp[parent] = count++;
Graph[mapTemp[parent]][mapTemp[son]] = 1;
}
DFS(1);
cout<<max(DP[1][0], DP[1][1])<<" ";
if( n == 1 ){
cout<<"Yes"<<endl;
continue;
}
if( n == 2 ){
cout<<"No"<<endl;
continue;
}
if( check() ){
cout<<"Yes"<<endl;
continue;
}
if(!check()){
cout<<"No"<<endl;
continue;
}
}
return 0;
}
最新文章
- SpringMVC中定时任务配置
- poj 3621 二分+spfa判负环
- Quartus 的管脚分配
- js对select动态添加和删除OPTION
- APC -- Asynchronous Procedure Call 异步过程调用
- H5与Activity之间的通信(调用)
- linux之sed用法【转载】
- 大数据笔记11:MapReduce的运行流程
- thinkphp 一些常用写法
- Java通过jxl解析Excel文件入库,及日期格式处理方式 (附源代码)
- combobox数据获取及使用总结
- PBRT笔记(14)——光线传播2:体积渲染
- Confluence 6 ";net.sf.hibernate.PropertyValueException: not-null"; 相关问题解决
- 蓝牙协议分析(9)_BLE安全机制之LL Privacy
- 设计模式之Interpreter(解释器)(转)
- Jenkins+sonar7.3集成
- Memcached 简单利用和简单了解(Mac的安装和使用)
- C#的字节与流
- mysql打印输出转csv格式
- node.js创建并引用模块