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 |
为啥讲findr()放到主函数里还是tle#include <cstdio> using namespace std; int N,M;//学生数量为N-1个,包括0; int data[30000]; int unit(int i,int j) { for (; data[j] >= 0; j = data[j]) ; if(data[i]< data[j]) { data[i] += data[j]; data[j] = i; return i; } else { data[j] += data[i]; data[i] = j; return j; } } int main() { while (scanf("%d %d",&N,&M),N) { for(int i =0;i<N;i++) data[i] = -1; for (int i = 0,j; i < M; i++) // 每组数据有两种情况 ,这一组单独成树或包含其他的树 { scanf("%d",&j); for (int k=0,s,t1=0,t2; k <j ; k++) { scanf("%d",&s); //输入 if(k == 0){ for (; data[s] >= 0; s = data[i]) ; t1 =s; } //第一颗树的根作为初始根 else { t1 = unit(t1,s); } } } int i = 0; for (; data[i] >= 0; i = data[i]) ; printf("%d\n",-(data[i])); } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator