@@ -11,14 +11,15 @@ static int minDist(int dist[], boolean[] set1) {
1111 }
1212 return min_index ;
1313 }
14- static final int OFFSET = -1 ; // Offset by 1 for adjancey matirix because index begins at 0
14+ static final int OFFSET = -1 ; // 0 /*Remove offset*/ by 1 for adjancey matirix because index begins at 0
1515 public static int [] root ;
1616 public static int status = -1 ;
1717 public static int [] arr ;
1818 public static int [] pasture ;
1919 //public static List<IPair> pastures = new ArrayList<IPair>();
2020 public static List <Integer > pastures = new ArrayList <Integer >();
2121 public static int [] dijkstra (int [][] graph1 , int startVertex ) {
22+ //Arrays.fill(root, 0);
2223 status = 0 ;
2324 int N = graph1 .length ;
2425 int [] dists = new int [N ];
@@ -53,8 +54,8 @@ public static int[] dijkstra(int[][] graph1, int startVertex) {
5354 //if(pastures.contains(new IPair(nearestVertex,vertexIndex))) {
5455
5556 //if(pastures.contains(nearestVertex) ) {
56- System .out .println ("Info: " +nearestVertex +" " +vertexIndex );
57- System .out .println ("Set " +(nearestVertex - 1 ) + " and " +(vertexIndex - 1 ));
57+ // System.out.println("Info: "+nearestVertex+" "+vertexIndex);
58+ // System.out.println("Set "+(nearestVertex - 1) + " and "+(vertexIndex - 1));
5859 //arr[nearestVertex] = 1;
5960 //arr[vertexIndex] = 1;
6061 /*
@@ -85,7 +86,7 @@ public static void main(String[] args) throws IOException{
8586 int N = Integer .parseInt (st .nextToken ());
8687 int M = Integer .parseInt (st .nextToken ());
8788 int K = Integer .parseInt (st .nextToken ());
88- int [][] matrix = new int [N ][N ];
89+ int [][] matrix = new int [N + 1 ][N + 1 ];
8990 arr = new int [N ];
9091 pasture = new int [N ];
9192 for (int i = 0 ; i < N ; i ++){
@@ -94,44 +95,44 @@ public static void main(String[] args) throws IOException{
9495 for (int i = 0 ; i < M ; i ++) {
9596 st = new StringTokenizer (f .readLine ());
9697 int x = Integer .parseInt (st .nextToken ()),y = Integer .parseInt (st .nextToken ()),z = Integer .parseInt (st .nextToken ());
97- matrix [x + OFFSET ][y + OFFSET ] = z ;
98- matrix [y + OFFSET ][x + OFFSET ] = z ;
98+ matrix [x + 0 /*Remove offset*/ ][y + 0 /*Remove offset*/ ] = z ;
99+ matrix [y + 0 /*Remove offset*/ ][x + 0 /*Remove offset*/ ] = z ;
99100 }
100101 //System.out.println(Arrays.deepToString(matrix).replaceAll("],*", "],\n"));
101102 // Dijkstra Modification begins here
102- int [] out = dijkstra (matrix , N -2 );
103+ int [] out = dijkstra (matrix , N -1 );
103104 for (int i = 0 ; i < K ; i ++) {
104105 st = new StringTokenizer (f .readLine ());
105106 int x = Integer .parseInt (st .nextToken ());
106107 int y = Integer .parseInt (st .nextToken ());
107- pasture [x -1 ] = y ;
108- x = x + OFFSET ;
108+ // pasture[x-1] = y;
109+ x = x + 0 /*Remove offset*/ ;
109110 for (int j = 0 ; j < N ; j ++) {
110111 if (matrix [j ][x ] != 0 ) {
111112 //System.out.println("Override 1 "+j+" "+x+" "+y);
112- matrix [j ][x ] = matrix [ j ] [x ] - y ;
113+ matrix [j ][x ] = out [x ] - y ;
113114 }
114115 if (matrix [x ][j ] != 0 ) {
115116 //System.out.println("Override 2 "+x+" "+j+" "+y);
116- matrix [x ][j ] = matrix [ x ][ j ] - y ;
117+ matrix [x ][j ] = out [ x ] - y ;
117118 }
118119
119120 }
120- pastures .add (x );
121+ // pastures.add(x);
121122 //pastures.add(new IPair(x,y));
122123
123124 }
124125 // End modification
125126 System .out .println ("Modifacation Complete" );
126- System .out .println (Arrays .deepToString (matrix ).replaceAll ("],*" , "],\n " ));
127- int [] out2 = dijkstra (matrix , N - 1 );
127+ // System.out.println(Arrays.deepToString(matrix).replaceAll("],*", "],\n"));
128+ int [] out2 = dijkstra (matrix , N );
128129
129130 //System.out.println(Arrays.toString(root));
130131 //System.out.println(Arrays.toString(out));
131132
132133 PrintWriter pw = new PrintWriter (new FileWriter ("dining.out" ));
133134 for (int k = 0 ; k < arr .length -1 ; k ++) {
134- if (out [k ] < = out2 [k ]) {
135+ if (out [k ] > = out2 [k ]) {
135136 pw .println ("1" );
136137 }else {
137138 pw .println ("0" );
0 commit comments