UVa1220 Party at Hali_Bula
2017-07-31 21:13
369 查看
题目描述
![](https://img-blog.csdn.net/20170731211144686?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvVlNFSkdGQg==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
树上最大独立集,解的唯一性。
树上最大独立集,解的唯一性。
#include<cstdio> #include<iostream> #include<cstring> #include<vector> #include<algorithm> #include<map> #include<string> using namespace std; const int maxn=210; int n,d[maxn][2]; bool f[maxn][2]; string yon[2]; vector<int> v[maxn]; int dp(int u){ d[u][0]=0;d[u][1]=1; f[u][0]=f[u][1]=1; for(int i=0;i<v[u].size();i++){ int& k=v[u][i]; dp(k); if(d[k][0]==d[k][1]) d[u][0]+=d[k][0],f[u][0]=0; else if(d[k][0]>d[k][1]) d[u][0]+=d[k][0],f[u][0]&=f[k][0]; else d[u][0]+=d[k][1],f[u][1]&=f[k][1]; d[u][1]+=d[k][0]; f[u][1]&=f[k][0]; } } int main(){ yon[1]="Yes"; yon[0]="No"; while(scanf("%d",&n)==1&&n){ map<string,int> mp; for(int i=0;i<=n;i++) v[i].clear(); int tot=1; string boss; cin>>boss; mp[boss]=0; for(int i=1;i<n;i++){ memset(d,-1,sizeof(d)); memset(f,0,sizeof(f)); string a,b; cin>>a>>b; if(!mp.count(a)) mp[a]=tot++; if(!mp.count(b)) mp[b]=tot++; v[mp[b]].push_back(mp[a]); } dp(0); if(d[0][0]==d[0][1]) cout<<d[0][0]<<" No\n"; else if(d[0][0]>d[0][1]) cout<<d[0][0]<<' '<<yon[f[0][0]]<<endl; else cout<<d[0][1]<<' '<<yon[f[0][1]]<<endl; } return 0; }
相关文章推荐
- UVA1220Party at Hali-Bula(树的最大独立集 + 唯一性判断)
- UVa 1220 Party at Hali-Bula
- UVa 1220 (树的最大独立集) Party at Hali-Bula
- UVa-1220 Party at Hali-Bula (最大独立集)
- UVa 1220 - Party at Hali-Bula(最大独立集)
- UVa - 1220 - Party at Hali-Bula ( 树形DP 求最大独立集 )
- UVA 1220 Party at Hali-Bula - ACM/ICPC Tehran 2006
- UVA-1220 Party at Hali-Bula
- UVA 1220 Party at Hali-Bula (树形dp--树的最大独立集)
- 100道动态规划——36 UVA 1220 Party at Hali-Bula 树形DP 最大独立集 思考欠妥
- UVA 1220 / HDOJ 2412 Party at Hali-Bula 树形DP
- UVa 1220:Party at Hali-Bula(DP)
- 【uva】1220 Party at Hali-Bula
- UVA - 1220 Party at Hali-Bula 树的最大独立集
- UVA1220 - Party at Hali-Bula
- UVa 1220 Party at Hali-Bula (树形DP,最大独立集)
- 【UVA1220】Party at Hali-Bula
- 【Uva 1220】Party at Hali-Bula
- Uva-1220-Party at Hali-Bula
- UVA 1220 Party at Hali-Bula(树的最大独立集)