Language: C++

#include <bits/stdc++.h>
using namespace std

int Main {

	public static void main(String[] args) {
	
      int N;
      cin >> N >> endl;
      Node v[] = new Node[N];
		int c[] = new int[N-1];
		for(int i=0;i<N;i++){
			v[i] = new Node(i);
		}
		Edge e[] = new Edge[N-1];
		for(int i=0;i<N-1;i++) {
          cin >> a >> b >> c >> endl;
			e[i] = new Edge[a-1],v[b-1],c);
		}
		int Q;
      cin >> Q >> endl;
		int K;
      cin >> K >> endl;
		int x[] = new int[Q];
		int y[] = new int[Q];
		for(int i=0;i<Q;i++) {
			cin >> x[i] >> endl;
			cin >> y[i] >> endl;
		}
		PriorityQueue<Node> searching = new PriorityQueue<>((u,w)->u.d>w.d?1:u.d<w.d?-1:0);
		PriorityQueue<Node> searched = new PriorityQueue<>((u,w)->u.d>w.d?1:u.d<w.d?-1:0);
		boolean used[] = new boolean[N];
		Arrays.fill(used, false);
		v[K-1].Reload_dist(0);
		used[K-1] = true;
		for(Edge connect:v[K-1].edges) {
			Node another = connect.Other_one(v[K-1]);
			another.Reload_dist(connect.cost);
			searching.add(another);
			used[another.id] = true;
		}
		searched.add(v[K-1]);

		Node vertex=null;
		while(searching.size()>0) {
			vertex = searching.poll();
			for(Edge connect:vertex.edges) {
				Node another = connect.Other_one(vertex);
				if(!used[another.id]) {
					another.Reload_dist(vertex.d + connect.cost);
					if(!searched.contains(another)){
						searching.add(another);
					}
					searched.add(vertex);
					used[another.id] = true;
				}
			}
		}
		long result = 0;
		for(int i=0;i<Q;i++) {
			result = v[x[i]-1].d + v[y[i]-1].d;
			out.println(result);
		}




		out.flush();
	}
}

void Node{
	int id;
	long d;
	Node prev = null;
	ArrayList<Edge> edges = new ArrayList<>();

	public Node(int id) {
		this.id = id;
		this.d = Integer.MAX_VALUE;
	}

	public void Reset() {
		this.d = Integer.MAX_VALUE;
		this.prev = null;
	}

	public void Reload_dist(long dist) {
		this.d = dist;
	}

	public void Reload_prev(Node v) {
		this.prev = v;
	}

	@Override public Node clone() {
		return new Node(this.id);
	}

	public void Connect(Edge e) {
		edges.add(e);
	}
}

void Edge{
	Node v1, v2;
	int cost;
	public Edge(Node id1,Node id2, int c) {
		this.v1 = id1;
		this.v2 = id2;
		this.cost = c;
		v1.Connect(this);
		v2.Connect(this);
	}

	public Node First_one() {
		return this.v1;
	}

	public Node Second_one() {
		return this.v2;
	}

	public Node Other_one(Node v) {
		if(v.equals(this.v1)) {
			return this.v2;
		}
		else {
			return this.v1;
		}
	}
}

void Graph{
	static Node[] nodes;
	static Edge[] edges;

	public Graph(Node[] v,Edge[] e) {
		Graph.nodes = v;
		Graph.edges = e;
	}

	public static int size() {
		return nodes.length;
	}

	public boolean Bellman_Ford(Node s) {
		boolean negative_loop[] = new boolean[size()];
		Arrays.fill(negative_loop, false);
		s.Reload_dist(0);
		for(int i=0;i<size();i++) {
			for(Node v : nodes) {
				for(Edge e : v.edges) {
					if((v.d != Long.MAX_VALUE && e.Other_one(v).d > v.d + e.cost)) {
						e.Other_one(v).Reload_dist(v.d + e.cost);
						negative_loop[e.Other_one(v).id] = true;
					}
					if(i==size()-1) {
						return true;
					}
				}
			}
		}
		return false;
	}

}



Compiler output:
a.cc:96:9: error: stray '@' in program
   96 |         @Override public Node clone() {
      |         ^
a.cc:2:20: error: expected ';' before 'int'
    2 | using namespace std
      |                    ^
      |                    ;
    3 | 
    4 | int Main {
      | ~~~                 
a.cc:6:9: error: expected primary-expression before 'public'
    6 |         public static void main(String[] args) {
      |         ^~~~~~
a.cc:6:9: error: expected '}' before 'public'
a.cc:4:10: note: to match this '{'
    4 | int Main {
      |          ^
a.cc:70:1: error: expected declaration before '}' token
   70 | }
      | ^
a.cc:72:6: error: variable or field 'Node' declared void
   72 | void Node{
      |      ^~~~
a.cc:73:9: error: expected primary-expression before 'int'
   73 |         int id;
      |         ^~~
a.cc:73:9: error: expected '}' before 'int'
a.cc:72:10: note: to match this '{'
   72 | void Node{
      |          ^
a.cc:75:9: error: 'Node' does not name a type
   75 |         Node prev = null;
      |         ^~~~
a.cc:76:9: error: 'ArrayList' does not name a type
   76 |         ArrayList<Edge> edges = new ArrayList<>();
      |         ^~~~~~~~~
a.cc:78:9: error: expected unqualified-id before 'public'
   78 |         public Node(int id) {
      |         ^~~~~~
a.cc:83:9: error: expected unqualified-id before 'public'
   83 |         public void Reset() {
      |         ^~~~~~
a.cc:88:9: error: expected unqualified-id before 'public'
   88 |         public void Reload_dist(long dist) {
      |         ^~~~~~
a.cc:92:9: error: expected unqualified-id before 'public'
   92 |         public void Reload_prev(Node v) {
      |         ^~~~~~
a.cc:96:10: error: 'Override' does not name a type
   96 |         @Override public Node clone() {
      |          ^~~~~~~~
a.cc:100:9: error: expected unqualified-id before 'public'
  100 |         public void Connect(Edge e) {
      |         ^~~~~~
a.cc:103:1: error: expected declaration before '}' token
  103 | }
      | ^
a.cc:105:6: error: variable or field 'Edge' declared void
  105 | void Edge{
      |      ^~~~
a.cc:106:9: error: 'Node' was not declared in this scope
  106 |         Node v1, v2;
      |         ^~~~
a.cc:106:14: error: expected '}' before 'v1'
  106 |         Node v1, v2;
      |              ^~
a.cc:105:10: note: to match this '{'
  105 | void Edge{
      |          ^
a.cc:108:9: error: expected unqualified-id before 'public'
  108 |         public Edge(Node id1,Node id2, int c) {
      |         ^~~~~~
a.cc:116:9: error: expected unqualified-id before 'public'
  116 |         public Node First_one() {
      |         ^~~~~~
a.cc:120:9: error: expected unqualified-id before 'public'
  120 |         public Node Second_one() {
      |         ^~~~~~
a.cc:124:9: error: expected unqualified-id before 'public'
  124 |         public Node Other_one(Node v) {
      |         ^~~~~~
a.cc:132:1: error: expected declaration before '}' token
  132 | }
      | ^
a.cc:134:6: error: variable or field 'Graph' declared void
  134 | void Graph{
      |      ^~~~~
a.cc:135:9: error: expected primary-expression before 'static'
  135 |         static Node[] nodes;
      |         ^~~~~~
a.cc:135:9: error: expected '}' before 'static'
a.cc:134:11: note: to match this '{'
  134 | void Graph{
      |           ^
a.cc:136:16: error: 'Edge' does not name a type
  136 |         static Edge[] edges;
      |                ^~~~
a.cc:138:9: error: expected unqualified-id before 'public'
  138 |         public Graph(Node[] v,Edge[] e) {
      |         ^~~~~~
a.cc:143:9: error: expected unqualified-id before 'public'
  143 |         public static int size() {
      |         ^~~~~~
a.cc:147:9: error: expected unqualified-id before 'public'
  147 |         public boolean Bellman_Ford(Node s) {
      |         ^~~~~~
a.cc:167:1: error: expected declaration before '}' token
  167 | }
      | ^