Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
再一次求神牛帮助,这个代码WA在哪#include<iostream> #include<string.h> #include<stdio.h> #include<vector> using namespace std; vector<int>edge[10001],f[10001]; bool used[10001],leaf[10001],visit[10001]; int dproot[10001],all[10001]; void DFS(int t) { int i,u; used[t]=true; for(i=0;i<f[t].size();i++) { u=f[t][i]; if(!used[u]) { edge[t].push_back(u); leaf[t]=false; visit[u]=true; DFS(u); } } } void solve(int root) { int i,minnode=0; visit[root]=true; if(leaf[root]) { dproot[root]=1; all[root]=0; return ; } for(i=0;i<edge[root].size();i++) { int v=edge[root][i]; if(!visit[v]) solve(v); dproot[root]+=all[v]; minnode+=dproot[v]; } dproot[root]+=1; all[root]=min(dproot[root],minnode); } int main() { int n,i,j,k,u,v,temp; while(cin>>n) { for(i=1;i<=n;i++) { edge[i].clear(); f[i].clear(); } memset(used,0,sizeof(used)); memset(leaf,true,sizeof(leaf)); memset(all,0,sizeof(all)); memset(dproot,0,sizeof(dproot)); memset(visit,false,sizeof(visit)); for(i=1;i<n;i++) { //cin>>u>>v; scanf("%d %d",&u,&v); f[u].push_back(v); f[v].push_back(u); } DFS(1); for(i=1;i<=n;i++) { if(!visit[i]) { temp=i; break; } } memset(visit,false,sizeof(visit)); solve(temp); cout<<all[temp]<<endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator