Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class klingonWarfare {
- public static void main(String[] args) {
- Scanner scan=new Scanner(System.in);
- int t=scan.nextInt();
- for(int tt=0;tt<t;tt++) {
- int aa=scan.nextInt(), bb=scan.nextInt();
- Tree a=new Tree(aa), b=new Tree(bb);
- for(int i=0;i<aa;i++) {
- int type=scan.next().charAt(0)-'A';
- int par=scan.nextInt();
- a.type[i]=type;
- if(par!=-1) a.cnct[par].add(i);
- }
- for(int i=0;i<bb;i++) {
- int type=scan.next().charAt(0)-'A';
- int par=scan.nextInt();
- b.type[i]=type;
- if(par!=-1) b.cnct[par].add(i);
- }
- }
- }
- static HashMap<Long,Integer> hashToSize;
- static class Tree {
- int n;
- int[] size,hash,type;
- ArrayList<Integer>[] cnct;
- Tree(int n) {
- this.n=n;
- size=new int[n];
- Arrays.fill(size,1);
- hash=new int[n];
- type=new int[n];
- cnct=new ArrayList[n];
- for(int i=0;i<n;i++) cnct[i]=new ArrayList<>();
- }
- void dfs(int at) {
- for(int nxt:cnct[at]) {
- dfs(nxt);
- size[at]+=size[nxt];
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement