Advertisement
Guest User

klingon warfare

a guest
Nov 13th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class klingonWarfare {
  4. public static void main(String[] args) {
  5. Scanner scan=new Scanner(System.in);
  6. int t=scan.nextInt();
  7. for(int tt=0;tt<t;tt++) {
  8. int aa=scan.nextInt(), bb=scan.nextInt();
  9. Tree a=new Tree(aa), b=new Tree(bb);
  10. for(int i=0;i<aa;i++) {
  11. int type=scan.next().charAt(0)-'A';
  12. int par=scan.nextInt();
  13. a.type[i]=type;
  14. if(par!=-1) a.cnct[par].add(i);
  15. }
  16. for(int i=0;i<bb;i++) {
  17. int type=scan.next().charAt(0)-'A';
  18. int par=scan.nextInt();
  19. b.type[i]=type;
  20. if(par!=-1) b.cnct[par].add(i);
  21. }
  22.  
  23. }
  24. }
  25. static HashMap<Long,Integer> hashToSize;
  26. static class Tree {
  27. int n;
  28. int[] size,hash,type;
  29. ArrayList<Integer>[] cnct;
  30. Tree(int n) {
  31. this.n=n;
  32. size=new int[n];
  33. Arrays.fill(size,1);
  34. hash=new int[n];
  35. type=new int[n];
  36. cnct=new ArrayList[n];
  37. for(int i=0;i<n;i++) cnct[i]=new ArrayList<>();
  38. }
  39. void dfs(int at) {
  40. for(int nxt:cnct[at]) {
  41. dfs(nxt);
  42. size[at]+=size[nxt];
  43. }
  44.  
  45. }
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement