#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;
}

最新文章

  1. SpringMVC中定时任务配置
  2. poj 3621 二分+spfa判负环
  3. Quartus 的管脚分配
  4. js对select动态添加和删除OPTION
  5. APC -- Asynchronous Procedure Call 异步过程调用
  6. H5与Activity之间的通信(调用)
  7. linux之sed用法【转载】
  8. 大数据笔记11:MapReduce的运行流程
  9. thinkphp 一些常用写法
  10. Java通过jxl解析Excel文件入库,及日期格式处理方式 (附源代码)
  11. combobox数据获取及使用总结
  12. PBRT笔记(14)——光线传播2:体积渲染
  13. Confluence 6 &quot;net.sf.hibernate.PropertyValueException: not-null&quot; 相关问题解决
  14. 蓝牙协议分析(9)_BLE安全机制之LL Privacy
  15. 设计模式之Interpreter(解释器)(转)
  16. Jenkins+sonar7.3集成
  17. Memcached 简单利用和简单了解(Mac的安装和使用)
  18. C#的字节与流
  19. mysql打印输出转csv格式
  20. node.js创建并引用模块

热门文章

  1. 前端换mac可以参考搭一下简单的环境
  2. macbook pro 开发帮助
  3. linux系统时间同步,硬件时钟和系统时间同步,时区的设置
  4. Tasker to proximity screen off
  5. oracle 取整的几种方法
  6. D-U-N-S申请流程
  7. MVC使用Entity Framework Code First,用漂亮表格显示1对多关系
  8. Tomcat与Gzip与缓存
  9. android 4.4删除短信
  10. Selenium2+python自动化29-js处理多窗口