Language: Java

import java.util.*;
import java.io.*;

public class Main
{
  static int[] sum = new int[200000];
  public static void main(String args[])throws IOException
  {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer tokenizer1 = new StringTokenizer(br.readLine());
    
    int n = Integer.parseInt(tokenizer1.nextToken());
    int q = Integer.parseInt(tokenizer1.nextToken());
    
    int[][] matrix = new int[n][n];
    int c1,c2;
    
    for(int i=0;i<n-1;i++)
    {
      StringTokenizer tokenizer2 = new StringTokenizer(br.readLine());
      int c1  = Integer.parseInt(tokenizer2.nextToken());
      int c2 = Integer.parseInt(tokenizer2.nextToken());
      
      matrix[c1][c2] = 1;
    }
    
    i
    for(int i=0;i<q;i++)
    {
       StringTokenizer tokenizer3 = new StringTokenizer(br.readLine());
       int c1  = Integer.parseInt(tokenizer3.nextToken());
       int c2 = Integer.parseInt(tokenizer3.nextToken());
       BFS(new Pair(c1,c2),matrix,n);
       
    }
    for(int i=0;i<n;i++)
    {
      System.out.print(sum[i]+" ");
    }
  }
  
  public static void BFS(Pair pair,int[][] matrix,int size)
  {
    private LinkedList<Integer> adj[];
    adj = new LinkedList[v]; 
        for (int i=0; i<size; ++i) 
            adj[i] = new LinkedList();
    for(int i=0;i<size;i++)
    {
      for(int j=0;j<size;j++)
      {
        if(matrix[i][j] == 1)
        {
          adj[i].add(j);
        }
      }
    }
    boolean visited = new boolean[size];
    LinkedList<Integer> queue = new LinkedList<Integer>();
    visited[pair.node] = 1;
    queue.add(pair.node);
    int value = pair.value;
    int s;
    
    while(queue.size() != 0)
    {
      s = queue.poll();
      sum[s] += value;
      Iterator<Integer> it = new adj[s].listIterator();
      while(it.hasNext())
      {
        int n1 = it.next();
        if(!visited[n1])
        {
          visited[n1] = true;
          queue.add(n1);
        }
      }
      
    }
  }
}

class Pair
{
  public int node;
  public int value;
  Pair(int node,int value)
  {
    this.node = node;
    this.value = value;
  }
}

Compiler output:
Main.java:27: error: not a statement
    i
    ^
Main.java:27: error: ';' expected
    i
     ^
Main.java:44: error: illegal start of expression
    private LinkedList<Integer> adj[];
    ^
Main.java:45: error: <identifier> expected
    adj = new LinkedList[v]; 
       ^
Main.java:46: error: illegal start of type
        for (int i=0; i<size; ++i) 
        ^
Main.java:46: error: > or ',' expected
        for (int i=0; i<size; ++i) 
                            ^
Main.java:46: error: illegal start of type
        for (int i=0; i<size; ++i) 
                              ^
Main.java:46: error: <identifier> expected
        for (int i=0; i<size; ++i) 
                                 ^
Main.java:47: error: ']' expected
            adj[i] = new LinkedList();
                ^
Main.java:47: error: ';' expected
            adj[i] = new LinkedList();
                 ^
Main.java:47: error: invalid method declaration; return type required
            adj[i] = new LinkedList();
                         ^
Main.java:48: error: illegal start of type
    for(int i=0;i<size;i++)
    ^
Main.java:48: error: > or ',' expected
    for(int i=0;i<size;i++)
                      ^
Main.java:48: error: <identifier> expected
    for(int i=0;i<size;i++)
                        ^
Main.java:60: error: ']' expected
    visited[pair.node] = 1;
            ^
Main.java:60: error: ';' expected
    visited[pair.node] = 1;
                ^
Main.java:60: error: <identifier> expected
    visited[pair.node] = 1;
                     ^
Main.java:61: error: <identifier> expected
    queue.add(pair.node);
             ^
Main.java:61: error: <identifier> expected
    queue.add(pair.node);
                       ^
Main.java:65: error: illegal start of type
    while(queue.size() != 0)
    ^
Main.java:65: error: <identifier> expected
    while(queue.size() != 0)
                    ^
Main.java:65: error: ';' expected
    while(queue.size() != 0)
                      ^
Main.java:82: error: class, interface, enum, or record expected
}
^
23 errors