Language: C++

import java.io.*;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Deque;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
 
class Main{
     
static final PrintWriter out=new PrintWriter(System.out);
static final int INF=Integer.MAX_VALUE;
 
public static class Edge{
int to;
int cost;
public Edge(int to){
this.to=to; cost=0;
}
public Edge(int to,int cost){
this.to=to; this.cost=cost;
}
}
 
public static class Pair{
int x;
int y;
public Pair(int x,int y){
this.x=x; this.y=y;
}
public static final Comparator<Pair> DISTANCE_ORDER=new Comp();
private static class Comp implements Comparator<Pair>{
public int compare(Pair p1,Pair p2){
return (p1.x>p2.x)?1:(p1.x<p2.x)?-1:0;
}
}
}
 
public static class MyArrayList extends ArrayList<Edge>{}
 
public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
String line="";
while((line=br.readLine())!=null&&!line.isEmpty()){
int n=Integer.parseInt(line.split(" ")[0]);
int k=Integer.parseInt(line.split(" ")[1]);
int[] c=new int[n];
int[] d=new int[n];
int[] dist=new int[n];
boolean[][] visited=new boolean[n][n];
MyArrayList[] array=new MyArrayList[n];
for(int i=0;i<n;i++){
st=new StringTokenizer(br.readLine());
c[i]=Integer.parseInt(st.nextToken());
d[i]=Integer.parseInt(st.nextToken());
array[i]=new MyArrayList();
}
MyArrayList[] carray=array.clone();
for(int i=0;i<k;i++){
st=new StringTokenizer(br.readLine());
int a=Integer.parseInt(st.nextToken())-1;
int b=Integer.parseInt(st.nextToken())-1;
array[a].add(new Edge(b));
array[b].add(new Edge(a));
}
for(int i=0;i<n;i++) bfs(i,d[i],visited,array);
for(int i=0;i<n;i++){
for(int j=0;j<n&&j!=i;j++){
if(visited[i][j]) carray[i].add(new Edge(j,c[i]));
}
}
dijkstra(dist,carray);
out.println(dist[n-1]);
}
out.flush();
}
 
public static void bfs(int s,int t,boolean[][] visited,MyArrayList[] array){
Arrays.fill(visited[s],false);
Deque<Pair> que=new ArrayDeque<Pair>();
que.offerLast(new Pair(s,t));
while(!que.isEmpty()){
Pair p=que.pollFirst();
int ns=p.x;
visited[s][ns]=true;
ArrayList<Edge> list=array[ns];
if(p.y<=0) continue;
for(int i=0;i<list.size();i++){
Edge e=list.get(i);
if(!visited[s][e.to]) que.offerLast(new Pair(e.to,p.y-1));
}
}
}
 
public static void dijkstra(int[] dist,MyArrayList[] array){
PriorityQueue<Pair> pque=new PriorityQueue<Pair>(1,Pair.DISTANCE_ORDER);
Arrays.fill(dist,INF);
dist[0]=0;
pque.offer(new Pair(0,0));
while(!pque.isEmpty()){
Pair p=pque.poll();
int v=p.y;
ArrayList<Edge> list=array[v];
if(dist[v]<p.x||list.size()==0) continue;
for(int i=0;i<list.size();i++){
Edge e=list.get(i);
if(dist[e.to]>dist[v]+e.cost){
dist[e.to]=dist[v]+e.cost;
pque.offer(new Pair(dist[e.to],e.to));
}
}
}
}
}

Compiler output:
a.cc:1:1: error: 'import' does not name a type
    1 | import java.io.*;
      | ^~~~~~
a.cc:1:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:2:1: error: 'import' does not name a type
    2 | import java.util.ArrayDeque;
      | ^~~~~~
a.cc:2:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:3:1: error: 'import' does not name a type
    3 | import java.util.ArrayList;
      | ^~~~~~
a.cc:3:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:4:1: error: 'import' does not name a type
    4 | import java.util.Arrays;
      | ^~~~~~
a.cc:4:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:5:1: error: 'import' does not name a type
    5 | import java.util.Comparator;
      | ^~~~~~
a.cc:5:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:6:1: error: 'import' does not name a type
    6 | import java.util.Deque;
      | ^~~~~~
a.cc:6:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:7:1: error: 'import' does not name a type
    7 | import java.util.PriorityQueue;
      | ^~~~~~
a.cc:7:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:8:1: error: 'import' does not name a type
    8 | import java.util.StringTokenizer;
      | ^~~~~~
a.cc:8:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:12:8: error: 'final' does not name a type
   12 | static final PrintWriter out=new PrintWriter(System.out);
      |        ^~~~~
a.cc:13:8: error: 'final' does not name a type
   13 | static final int INF=Integer.MAX_VALUE;
      |        ^~~~~
a.cc:15:7: error: expected ':' before 'static'
   15 | public static class Edge{
      |       ^~~~~~~
      |       :
a.cc:18:7: error: expected ':' before 'Edge'
   18 | public Edge(int to){
      |       ^~~~~
      |       :
a.cc:21:7: error: expected ':' before 'Edge'
   21 | public Edge(int to,int cost){
      |       ^~~~~
      |       :
a.cc:24:2: error: expected ';' after class definition
   24 | }
      |  ^
      |  ;
a.cc:15:8: error: a storage class can only be specified for objects and functions
   15 | public static class Edge{
      |        ^~~~~~
a.cc:26:7: error: expected ':' before 'static'
   26 | public static class Pair{
      |       ^~~~~~~
      |       :
a.cc:29:7: error: expected ':' before 'Pair'
   29 | public Pair(int x,int y){
      |       ^~~~~
      |       :
a.cc:32:7: error: expected ':' before 'static'
   32 | public static final Comparator<Pair> DISTANCE_ORDER=new Comp();
      |       ^~~~~~~
      |       :
a.cc:32:15: error: 'final' does not name a type
   32 | public static final Comparator<Pair> DISTANCE_ORDER=new Comp();
      |               ^~~~~
a.cc:33:8: error: expected ':' before 'static'
   33 | private static class Comp implements Comparator<Pair>{
      |        ^~~~~~~
      |        :
a.cc:33:27: error: expected ';' at end of member declaration
   33 | private static class Comp implements Comparator<Pair>{
      |                           ^~~~~~~~~~
      |                                     ;
a.cc:33:38: error: 'Comparator' does not name a type
   33 | private static class Comp implements Comparator<Pair>{
      |                                      ^~~~~~~~~~
a.cc:38:2: error: expected ';' after class definition
   38 | }
      |  ^
      |  ;
a.cc:26:8: error: a storage class can only be specified for objects and functions
   26 | public static class Pair{
      |        ^~~~~~
a.cc:40:7: error: expected ':' before 'static'
   40 | public static class MyArrayList extends ArrayList<Edge>{}
      |       ^~~~~~~
      |       :
a.cc:40:33: error: expected ';' at end of member declaration
   40 | public static class MyArrayList extends ArrayList<Edge>{}
      |                                 ^~~~~~~
      |                                        ;
a.cc:40:41: error: 'ArrayList' does not name a type; did you mean 'MyArrayList'?
   40 | public static class MyArrayList extends ArrayList<Edge>{}
      |                                         ^~~~~~~~~
      |                                         MyArrayList
a.cc:42:7: error: expected ':' before 'static'
   42 | public static void main(String[] args) throws IOException{
      |       ^~~~~~~
      |       :
a.cc:42:25: error: 'String' has not been declared
   42 | public static void main(String[] args) throws IOException{
      |                         ^~~~~~
a.cc:42:34: error: expected ',' or '...' before 'args'
   42 | public static void main(String[] args) throws IOException{
      |                                  ^~~~
a.cc:42:38: error: expected ';' at end of member declaration
   42 | public static void main(String[] args) throws IOException{
      |                                      ^
      |                                       ;
a.cc:42:40: error: 'throws' does not name a type
   42 | public static void main(String[] args) throws IOException{
      |                                        ^~~~~~
a.cc:80:7: error: expected ':' before 'static'
   80 | public static void bfs(int s,int t,boolean[][] visited,MyArrayList[] array){
      |       ^~~~~~~
      |       :
a.cc:80:36: error: 'boolean' has not been declared
   80 | public static void bfs(int s,int t,boolean[][] visited,MyArrayList[] array){
      |                                    ^~~~~~~
a.cc:80:46: error: multidimensional array must have bounds for all dimensions except the first
   80 | public static void bfs(int s,int t,boolean[][] visited,MyArrayList[] array){
      |                                              ^
a.cc:80:48: error: expected ',' or '...' before 'visited'
   80 | public static void bfs(int s,int t,boolean[][] visited,MyArrayList[] array){
      |                                                ^~~~~~~
a.cc:97:7: error: expected ':' before 'static'
   97 | public static void dijkstra(int[] dist,MyArrayList[] array){
      |       ^~~~~~~
      |       :
a.cc:97:35: error: expected ',' or '...' before 'dist'
   97 | public static void dijkstra(int[] dist,MyArrayList[] array){
      |                                   ^~~~
a.cc:116:2: error: expected ';' after class definition
  116 | }
      |  ^
      |  ;
a.cc: In constructor 'Main::Edge::Edge(int)':
a.cc:19:6: error: request for member 'to' in '(Main::Edge*)this', which is of pointer type 'Main::Edge*' (maybe you meant to use '->' ?)
   19 | this.to=to; cost=0;
      |      ^~
a.cc: In constructor 'Main::Edge::Edge(int, int)':
a.cc:22:6: error: request for member 'to' in '(Main::Edge*)this', which is of pointer type 'Main::Edge*' (maybe you meant to use '->' ?)
   22 | this.to=to; this.cost=cost;
      |      ^~
a.cc:22:18: error: request for member 'cost' in '(Main::Edge*)this', which is of pointer type 'Main::Edge*' (maybe you meant to use '->' ?)
   22 | this.to=to; this.cost=cost;
      |                  ^~~~
a.cc: In constructor 'Main::Pair::Pair(int, int)':
a.cc:30:6: error: request for member 'x' in '(Main::Pair*)this', which is of pointer type 'Main::Pair*' (maybe you meant to use '->' ?)
   30 | this.x=x; this.y=y;
      |      ^
a.cc:30:16: error: request for member 'y' in '(Main::Pair*)this', which is of pointer type 'Main::Pair*' (maybe you meant to use '->' ?)
   30 | this.x=x; this.y=y;
      |                ^
a.cc: In static member function 'static void Main::bfs(...)':
a.cc:81:1: error: 'Arrays' was not declared in this scope
   81 | Arrays.fill(visited[s],false);
      | ^~~~~~
a.cc:81:13: error: 'visited' was not declared in this scope
   81 | Arrays.fill(visited[s],false);
      |             ^~~~~~~
a.cc:82:1: error: 'Deque' was not declared in this scope
   82 | Deque<Pair> que=new ArrayDeque<Pair>();
      | ^~~~~
a.cc:82:11: error: expected primary-expression before '>' token
   82 | Deque<Pair> que=new ArrayDeque<Pair>();
      |           ^
a.cc:82:13: error: 'que' was not declared in this scope
   82 | Deque<Pair> que=new ArrayDeque<Pair>();
      |             ^~~
a.cc:82:21: error: 'ArrayDeque' does not name a type
   82 | Deque<Pair> que=new ArrayDeque<Pair>();
      |                     ^~~~~~~~~~
a.cc:82:36: error: expected primary-expression before '>' token
   82 | Deque<Pair> que=new ArrayDeque<Pair>();
      |                                    ^
a.cc:82:38: error: expected primary-expression before ')' token
   82 | Deque<Pair> que=new ArrayDeque<Pair>();
      |                                      ^
a.cc:86:10: error: 'int Main::Pair::x' is private within this context
   86 | int ns=p.x;
      |          ^
a.cc:27:5: note: declared private here
   27 | int x;
      |     ^
a.cc:88:1: error: 'ArrayList' was not declared in this scope; did you mean 'MyArrayList'?
   88 | ArrayList<Edge> list=array[ns];
      | ^~~~~~~~~
      | MyArrayList
a.cc:88:15: error: expected primary-expression before '>' token
   88 | ArrayList<Edge> list=array[ns];
      |               ^
a.cc:88:17: error: 'list' was not declared in this scope
   88 | ArrayList<Edge> list=array[ns];
      |                 ^~~~
a.cc:88:22: error: 'array' was not declared in this scope
   88 | ArrayList<Edge> list=array[ns];
      |                      ^~~~~
a.cc:89:6: error: 'int Main::Pair::y' is private within this context
   89 | if(p.y<=0) continue;
      |      ^
a.cc:28:5: note: declared private here
   28 | int y;
      |     ^
a.cc:92:18: error: 'int Main::Edge::to' is private within this context
   92 | if(!visited[s][e.to]) que.offerLast(new Pair(e.to,p.y-1));
      |                  ^~
a.cc:16:5: note: declared private here
   16 | int to;
      |     ^~
a.cc:92:48: error: 'int Main::Edge::to' is private within this context
   92 | if(!visited[s][e.to]) que.offerLast(new Pair(e.to,p.y-1));
      |                                                ^~
a.cc:16:5: note: declared private here
   16 | int to;
      |     ^~
a.cc:92:53: error: 'int Main::Pair::y' is private within this context
   92 | if(!visited[s][e.to]) que.offerLast(new Pair(e.to,p.y-1));
      |                                                     ^
a.cc:28:5: note: declared private here
   28 | int y;
      |     ^
a.cc: In static member function 'static void Main::dijkstra(int*)':
a.cc:98:1: error: 'PriorityQueue' was not declared in this scope
   98 | PriorityQueue<Pair> pque=new PriorityQueu