Title: http://www.lydsy.com/JudgeOnline/problem.php?id=1086
Exercises
Worship popoqqq:http://blog.csdn.net/popoqqq/article/details/42772237
This distinguishes to meet the test instructions, but some blocks are not unicom.
Code:
1#include <cstdio>2#include <cstdlib>3#include <cmath>4#include <cstring>5#include <algorithm>6#include <iostream>7#include <vector>8#include <map>9#include <Set>Ten#include <queue> One#include <string> A #defineINF 1000000000 - #defineMAXN 1000+5 - #defineMAXM 100000+5 the #defineEPS 1e-10 - #definell Long Long - #definePA pair<int,int> - #defineFor0 (i,n) for (int i=0;i<= (n); i++) + #defineFor1 (i,n) for (int i=1;i<= (n); i++) - #defineFor2 (i,x,y) for (int i= (x); i<= (y); i++) + #defineFor3 (i,x,y) for (int i= (x); i>= (y); i--) A #defineFor4 (i,x) for (int i=head[x],y=e[i].go;i;i=e[i].next,y=e[i].go) at #defineMoD 1000000007 - using namespacestd; -InlineintRead () - { - intx=0, f=1;CharCh=GetChar (); - while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} in while(ch>='0'&&ch<='9') {x=Ten*x+ch-'0'; ch=GetChar ();} - returnx*F; to } + intN,M,TOT,TOP,HEAD[MAXN],BELONG[MAXN],STA[MAXN],CNT,RT[MAXN]; - structedge{intGo,next;} e[2*MAXN]; theInlinevoidAddintXinty) * { $E[++tot]= (Edge) {y,head[x]};head[x]=tot;Panax NotoginsengE[++tot]= (Edge) {x,head[y]};head[y]=tot; - } theInlinevoidDfsintXintFA) + { A inttmp=top; theFor4 (i,x)if(y!=FA) + { - DFS (y,x); $ if(top-tmp>=m) $ { -rt[++cnt]=x; - while(top!=tmp) belong[sta[top--]]=CNT; the } - }Wuyista[++top]=x; the } - intMain () Wu { -Freopen ("Input.txt","R", stdin); AboutFreopen ("output.txt","W", stdout); $N=read (); m=read (); -For1 (i,n-1) Add (read (), read ()); -Dfs1,0); - while(top) belong[sta[top--]]=CNT; Aprintf"%d\n", CNT); +For1 (i,n) printf ("%d%c", Belong[i],i==n?'\ n':' '); theFor1 (i,cnt) printf ("%d%c", rt[i],i==cnt?'\ n':' '); - return 0; $}View Code
BZOJ1086: [SCOI2005] Royal Confederation