The largest independent set of trees, but to determine uniqueness. Some are like Dfs. Also found Std::ios::sync_with_stdio (0) can not be used with scanf!
1#include <cstdio>2#include <cstring>3#include <iostream>4#include <string>5#include <vector>6#include <map>7 #definePB Push_back8 using namespacestd;9 Const intmaxn=205;Ten intN; One stringa[3][MAXN]; Amap<string,int>MP; -vector<int>VT[MAXN]; - intdpintUintPBOOL&f) the { -f=1; - intans=p; - if(p==1) for(intI=0; I<vt[u].size (); i++)//If you select U, then the child nodes of U cannot be selected. + { - intv=Vt[u][i]; + BOOLT; AANS+=DP (V,0, T); at if(t==0) f=0; - } - Else for(intI=0; I<vt[u].size (); i++)//If no U is selected, then its child nodes can be selected or not selected. - { - intv=Vt[u][i]; - BOOLt1,t2; in intD1=DP (V,0, T1), D2=DP (V,1, T2); -ans+=Max (D1,D2); to if((D1>D2&&!T1) | | (D1<D2&&!T2) | | (D1==D2)) f=0; + } - returnans; the } * intMain () $ {Panax Notoginseng while(SCANF ("%d", &n) &&N) - { the mp.clear (); + for(intI=1; i<=n;i++) A { thecin>>a[1][i]; + if(i>1) cin>>a[2][i]; -mp[a[1][i]]=i; $ vt[i].clear (); $ } - for(intI=2; i<=n;i++) -vt[mp[a[2][I]]].PB (i); the BOOLt1,t2; - intD1=DP (1,0, T1), D2=DP (1,1, T2);Wuyiprintf"%d", Max (D1,D2)); the if((D1>D2&&T1) | | (D2>D1&&T2)) printf"yes\n"); - Elseprintf"no\n"); Wu } -}
Uva-1220-party at Hali-bula