import java.util.*;
public class Main{
public static class Edge {
public int u,v,cost;
public Edge(int _u,int _v,int _cost) {
u = _u;
v = _v;
cost = _cost;
}
}
static int n,m;
static int[] pre;
static ArrayList <Edge> edges;
static boolean SP() {
pre[0] = 0;
for (int i = 1 ; i <= n ; i++)
pre[i] = Integer.MAX_VALUE;
for (int i = 0 ; i < n ; i++) {
for (Edge j : edges) {
int val = pre[j.u] + j.cost;
pre[j.v] = Math.min(val,pre[j.v]);
}
}
for (Edge j : edges) {
int val = pre[j.u] + j.cost;
if (pre[j.v] > val)
return false;
}
return true;
}
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
n = scan.nextInt();
m = scan.nextInt();
edges = new ArrayList<Edge>();
pre = new int[n+1];
for (int i = 1 ; i <= n ; i++) {
edges.add(new Edge(i-1,i,1));
edges.add(new Edge(i,i-1,0));
}
while((m--) != 0) {
int l = scan.nextInt();
int r = scan.nextInt();
int k = scan.nextInt();
int val = scan.nextInt();
l++;
r++;
if (val == 0)
edges.add(new Edge(l-1,r,r-l-k+1));
else
edges.add(new Edge(r,l-1,-(r-l-k+1)));
}
if (SP() == false)
System.out.println(-1);
else {
for (int i = n ; i >= 1 ; i--)
pre[i] -= pre[i - 1];
for (int i = 1 ; i <= n ; i++)
System.out.printf("%d ",pre[i]);
System.out.println();
}
}
}
Compilation message
restore.java:2: error: class Main is public, should be declared in a file named Main.java
public class Main{
^
1 error