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 |
我这java代码怎么会是wrong answer 啊?哪位大神帮看下啊。。。import java.util.Scanner; public class Main { public static int[] parent =new int[30005]; public static int[] deep=new int[30005];//the length to father public static int[] amount=new int[30005]; public static void make_set(){ for(int i=0;i<amount.length;i++){ parent[i]=i; deep[i]=0; amount[i]=1; } } public static int findhead(int x){ if(x!=parent[x]){ int temp=parent[x]; parent[x]=findhead(parent[x]); deep[x]+=deep[temp]; } return parent[x]; } public static void move_set(int x,int y){ int px=findhead(x); int py=findhead(y); parent[py]=px; deep[py]=amount[x]; amount[px]+=amount[py]; } /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner cin=new Scanner(System.in); int line=Integer.parseInt(cin.nextLine()); //long startTime=System.nanoTime(); make_set(); while(line--!=0){ String str=cin.nextLine(); String[] array=str.split("\\s+"); if(array[0].equals("M")){ move_set(Integer.parseInt(array[1]), Integer.parseInt(array[2])); } else { int x=Integer.parseInt(array[1]); int px=findhead(x); System.out.println(amount[px]-deep[x]-1); } } } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator