Language: C++

import java.io.*;
import java.util.Arrays;
   
class Main{
   
static final int INF=Integer.MAX_VALUE/2;
static final PrintWriter out=new PrintWriter(System.out);
   
   
static class Edge{
int from;
int to;
int cost;
Edge(int from,int to,int cost){
this.from=from; this.to=to; this.cost=cost;
}
}
   
public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String line="";
while((line=br.readLine())!=null&&!line.isEmpty()){
int v=Integer.parseInt(line.split(" ")[0]);
int e=Integer.parseInt(line.split(" ")[1]);
int r=Integer.parseInt(line.split(" ")[2]);
boolean neg=false;
Edge[] es=new Edge[e];
int[] d=new int[v];
for(int i=0;i<e;i++){
line=br.readLine();
int s=Integer.parseInt(line.split(" ")[0]);
int t=Integer.parseInt(line.split(" ")[1]);
int c=Integer.parseInt(line.split(" ")[2]);
es[i]=new Edge(s,t,c);
}
BellmanFord(v,e,r,neg,es,d);
if(neg){
out.println("NEGATIVE CYCLE");
}
else{
for(int i=0;i<v;i++){
if(d[i]==INF){
out.println("INF");
}
else{
out.println(d[i]);
}
}
}
out.flush();
}
}
   
private static void BellmanFord(int v,int ee,int r,boolean neg,Edge[] es,int[] d){
Arrays.fill(d,INF);
d[r]=0;
for(int i=0;i<v;i++){
boolean update=false;
for(int j=0;j<ee;j++){
Edge e=es[j];
if(d[e.to]>d[e.from]+e.cost){
d[e.to]=d[e.from]+e.cost;
update=true;
if(i==v-1){
neg=true;
break;
}
}
}
if(!update){
break;
}
}
}
}

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.Arrays;
      | ^~~~~~
a.cc:2:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:6:8: error: 'final' does not name a type
    6 | static final int INF=Integer.MAX_VALUE/2;
      |        ^~~~~
a.cc:7:8: error: 'final' does not name a type
    7 | static final PrintWriter out=new PrintWriter(System.out);
      |        ^~~~~
a.cc:17:2: error: expected ';' after class definition
   17 | }
      |  ^
      |  ;
a.cc:10:1: error: a storage class can only be specified for objects and functions
   10 | static class Edge{
      | ^~~~~~
a.cc:19:7: error: expected ':' before 'static'
   19 | public static void main(String[] args) throws IOException{
      |       ^~~~~~~
      |       :
a.cc:19:25: error: 'String' has not been declared
   19 | public static void main(String[] args) throws IOException{
      |                         ^~~~~~
a.cc:19:34: error: expected ',' or '...' before 'args'
   19 | public static void main(String[] args) throws IOException{
      |                                  ^~~~
a.cc:19:38: error: expected ';' at end of member declaration
   19 | public static void main(String[] args) throws IOException{
      |                                      ^
      |                                       ;
a.cc:19:40: error: 'throws' does not name a type
   19 | public static void main(String[] args) throws IOException{
      |                                        ^~~~~~
a.cc:54:8: error: expected ':' before 'static'
   54 | private static void BellmanFord(int v,int ee,int r,boolean neg,Edge[] es,int[] d){
      |        ^~~~~~~
      |        :
a.cc:54:52: error: 'boolean' has not been declared
   54 | private static void BellmanFord(int v,int ee,int r,boolean neg,Edge[] es,int[] d){
      |                                                    ^~~~~~~
a.cc:54:71: error: expected ',' or '...' before 'es'
   54 | private static void BellmanFord(int v,int ee,int r,boolean neg,Edge[] es,int[] d){
      |                                                                       ^~
a.cc:75:2: error: expected ';' after class definition
   75 | }
      |  ^
      |  ;
a.cc: In constructor 'Main::Edge::Edge(int, int, int)':
a.cc:15:6: error: request for member 'from' in '(Main::Edge*)this', which is of pointer type 'Main::Edge*' (maybe you meant to use '->' ?)
   15 | this.from=from; this.to=to; this.cost=cost;
      |      ^~~~
a.cc:15:22: error: request for member 'to' in '(Main::Edge*)this', which is of pointer type 'Main::Edge*' (maybe you meant to use '->' ?)
   15 | this.from=from; this.to=to; this.cost=cost;
      |                      ^~
a.cc:15:34: error: request for member 'cost' in '(Main::Edge*)this', which is of pointer type 'Main::Edge*' (maybe you meant to use '->' ?)
   15 | this.from=from; this.to=to; this.cost=cost;
      |                                  ^~~~
a.cc: In static member function 'static void Main::BellmanFord(int, int, int, int, Edge*)':
a.cc:55:1: error: 'Arrays' was not declared in this scope
   55 | Arrays.fill(d,INF);
      | ^~~~~~
a.cc:55:13: error: 'd' was not declared in this scope
   55 | Arrays.fill(d,INF);
      |             ^
a.cc:55:15: error: 'INF' was not declared in this scope
   55 | Arrays.fill(d,INF);
      |               ^~~
a.cc:58:1: error: 'boolean' was not declared in this scope; did you mean 'bool'?
   58 | boolean update=false;
      | ^~~~~~~
      | bool
a.cc:60:8: error: 'es' was not declared in this scope; did you mean 'e'?
   60 | Edge e=es[j];
      |        ^~
      |        e
a.cc:61:8: error: 'int Main::Edge::to' is private within this context
   61 | if(d[e.to]>d[e.from]+e.cost){
      |        ^~
a.cc:12:5: note: declared private here
   12 | int to;
      |     ^~
a.cc:61:16: error: 'int Main::Edge::from' is private within this context
   61 | if(d[e.to]>d[e.from]+e.cost){
      |                ^~~~
a.cc:11:5: note: declared private here
   11 | int from;
      |     ^~~~
a.cc:61:24: error: 'int Main::Edge::cost' is private within this context
   61 | if(d[e.to]>d[e.from]+e.cost){
      |                        ^~~~
a.cc:13:5: note: declared private here
   13 | int cost;
      |     ^~~~
a.cc:62:5: error: 'int Main::Edge::to' is private within this context
   62 | d[e.to]=d[e.from]+e.cost;
      |     ^~
a.cc:12:5: note: declared private here
   12 | int to;
      |     ^~
a.cc:62:13: error: 'int Main::Edge::from' is private within this context
   62 | d[e.to]=d[e.from]+e.cost;
      |             ^~~~
a.cc:11:5: note: declared private here
   11 | int from;
      |     ^~~~
a.cc:62:21: error: 'int Main::Edge::cost' is private within this context
   62 | d[e.to]=d[e.from]+e.cost;
      |                     ^~~~
a.cc:13:5: note: declared private here
   13 | int cost;
      |     ^~~~
a.cc:63:1: error: 'update' was not declared in this scope
   63 | update=true;
      | ^~~~~~
a.cc:70:5: error: 'update' was not declared in this scope
   70 | if(!update){
      |     ^~~~~~