| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 69044f9 commit fff71eb
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,63 +1,63 @@ | |||
| 1 | 1 | 1 | |
| 2 | - 1 | ||
| 3 | - 1 | ||
| 4 | - 1 | ||
| 5 | - 1 | ||
| 6 | - 1 | ||
| 7 | 2 | 0 | |
| 8 | 3 | 0 | |
| 9 | - 1 | ||
| 10 | - 1 | ||
| 11 | - 1 | ||
| 12 | - 1 | ||
| 13 | - 1 | ||
| 14 | - 1 | ||
| 15 | 4 | 0 | |
| 16 | 5 | 0 | |
| 17 | - 1 | ||
| 18 | - 1 | ||
| 19 | - 1 | ||
| 20 | - 1 | ||
| 21 | - 1 | ||
| 22 | - 1 | ||
| 23 | 6 | 0 | |
| 24 | 7 | 0 | |
| 25 | 8 | 1 | |
| 26 | 9 | 1 | |
| 27 | - 1 | ||
| 28 | - 1 | ||
| 29 | - 1 | ||
| 30 | - 1 | ||
| 31 | 10 | 0 | |
| 32 | 11 | 0 | |
| 33 | - 1 | ||
| 34 | - 1 | ||
| 35 | - 1 | ||
| 36 | - 1 | ||
| 37 | - 1 | ||
| 38 | - 1 | ||
| 39 | - 1 | ||
| 40 | 12 | 0 | |
| 41 | - 1 | ||
| 42 | - 1 | ||
| 43 | - 1 | ||
| 44 | - 1 | ||
| 45 | - 1 | ||
| 46 | - 1 | ||
| 47 | - 1 | ||
| 13 | + 0 | ||
| 14 | + 0 | ||
| 48 | 15 | 0 | |
| 49 | 16 | 1 | |
| 50 | 17 | 1 | |
| 51 | - 1 | ||
| 52 | - 1 | ||
| 53 | - 1 | ||
| 54 | - 1 | ||
| 55 | - 1 | ||
| 18 | + 0 | ||
| 19 | + 0 | ||
| 20 | + 0 | ||
| 21 | + 0 | ||
| 22 | + 0 | ||
| 56 | 23 | 0 | |
| 57 | 24 | 1 | |
| 58 | 25 | 1 | |
| 26 | + 0 | ||
| 27 | + 0 | ||
| 28 | + 0 | ||
| 29 | + 0 | ||
| 30 | + 0 | ||
| 31 | + 0 | ||
| 59 | 32 | 1 | |
| 60 | 33 | 1 | |
| 34 | + 0 | ||
| 35 | + 0 | ||
| 36 | + 0 | ||
| 37 | + 0 | ||
| 38 | + 0 | ||
| 39 | + 0 | ||
| 40 | + 0 | ||
| 61 | 41 | 1 | |
| 42 | + 0 | ||
| 43 | + 0 | ||
| 44 | + 0 | ||
| 45 | + 0 | ||
| 46 | + 0 | ||
| 47 | + 0 | ||
| 48 | + 0 | ||
| 62 | 49 | 1 | |
| 50 | + 0 | ||
| 51 | + 0 | ||
| 52 | + 0 | ||
| 53 | + 0 | ||
| 54 | + 0 | ||
| 55 | + 0 | ||
| 56 | + 0 | ||
| 63 | 57 | 1 | |
| 58 | + 0 | ||
| 59 | + 0 | ||
| 60 | + 0 | ||
| 61 | + 0 | ||
| 62 | + 0 | ||
| 63 | + 0 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,14 +11,15 @@ static int minDist(int dist[], boolean[] set1) { | |||
| 11 | 11 | } | |
| 12 | 12 | return min_index; | |
| 13 | 13 | } | |
| 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 | ||
| 15 | 15 | public static int[] root; | |
| 16 | 16 | public static int status = -1; | |
| 17 | 17 | public static int[] arr; | |
| 18 | 18 | public static int[] pasture; | |
| 19 | 19 | //public static List<IPair> pastures = new ArrayList<IPair>(); | |
| 20 | 20 | public static List<Integer> pastures = new ArrayList<Integer>(); | |
| 21 | 21 | public static int[] dijkstra(int[][] graph1, int startVertex) { | |
| 22 | + //Arrays.fill(root, 0); | ||
| 22 | 23 | status = 0; | |
| 23 | 24 | int N = graph1.length; | |
| 24 | 25 | int[] dists = new int[N]; | |
@@ -53,8 +54,8 @@ public static int[] dijkstra(int[][] graph1, int startVertex) { | |||
| 53 | 54 | //if(pastures.contains(new IPair(nearestVertex,vertexIndex))) { | |
| 54 | 55 | ||
| 55 | 56 | //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)); | ||
| 58 | 59 | //arr[nearestVertex] = 1; | |
| 59 | 60 | //arr[vertexIndex] = 1; | |
| 60 | 61 | /* | |
@@ -85,7 +86,7 @@ public static void main(String[] args) throws IOException{ | |||
| 85 | 86 | int N = Integer.parseInt(st.nextToken()); | |
| 86 | 87 | int M = Integer.parseInt(st.nextToken()); | |
| 87 | 88 | int K = Integer.parseInt(st.nextToken()); | |
| 88 | - int[][] matrix = new int[N][N]; | ||
| 89 | + int[][] matrix = new int[N+1][N+1]; | ||
| 89 | 90 | arr = new int[N]; | |
| 90 | 91 | pasture = new int[N]; | |
| 91 | 92 | for(int i = 0; i < N; i++){ | |
@@ -94,44 +95,44 @@ public static void main(String[] args) throws IOException{ | |||
| 94 | 95 | for(int i = 0; i < M; i ++) { | |
| 95 | 96 | st = new StringTokenizer(f.readLine()); | |
| 96 | 97 | 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; | ||
| 99 | 100 | } | |
| 100 | 101 | //System.out.println(Arrays.deepToString(matrix).replaceAll("],*", "],\n")); | |
| 101 | 102 | // Dijkstra Modification begins here | |
| 102 | - int[] out = dijkstra(matrix, N-2); | ||
| 103 | + int[] out = dijkstra(matrix, N-1); | ||
| 103 | 104 | for(int i = 0; i < K; i++) { | |
| 104 | 105 | st = new StringTokenizer(f.readLine()); | |
| 105 | 106 | int x = Integer.parseInt(st.nextToken()); | |
| 106 | 107 | 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*/; | ||
| 109 | 110 | for(int j = 0; j < N; j++) { | |
| 110 | 111 | if(matrix[j][x] != 0) { | |
| 111 | 112 | //System.out.println("Override 1 "+j+" "+x+" "+y); | |
| 112 | - matrix[j][x] = matrix[j][x] - y; | ||
| 113 | + matrix[j][x] = out[x] - y; | ||
| 113 | 114 | } | |
| 114 | 115 | if(matrix[x][j] != 0) { | |
| 115 | 116 | //System.out.println("Override 2 "+x+" "+j+" "+y); | |
| 116 | - matrix[x][j] = matrix[x][j] - y; | ||
| 117 | + matrix[x][j] = out[x] - y; | ||
| 117 | 118 | } | |
| 118 | 119 | ||
| 119 | 120 | } | |
| 120 | - pastures.add(x); | ||
| 121 | + //pastures.add(x); | ||
| 121 | 122 | //pastures.add(new IPair(x,y)); | |
| 122 | 123 | ||
| 123 | 124 | } | |
| 124 | 125 | // End modification | |
| 125 | 126 | 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); | ||
| 128 | 129 | ||
| 129 | 130 | //System.out.println(Arrays.toString(root)); | |
| 130 | 131 | //System.out.println(Arrays.toString(out)); | |
| 131 | 132 | ||
| 132 | 133 | PrintWriter pw = new PrintWriter(new FileWriter("dining.out")); | |
| 133 | 134 | for(int k = 0; k < arr.length -1; k ++) { | |
| 134 | - if(out[k] <= out2[k]) { | ||
| 135 | + if(out[k] >= out2[k]) { | ||
| 135 | 136 | pw.println("1"); | |
| 136 | 137 | }else { | |
| 137 | 138 | pw.println("0"); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments