You are viewing a single comment's thread. Return to all comments →
I can't seem to find the source of my error, if someone can help please, my tests succeed in the IDE but fail here
import java.util.Scanner; public class app { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String firstLine = scanner.nextLine(); String[] ar = firstLine.split(" "); int n = Integer.parseInt(ar[0]); int m = Integer.parseInt(ar[1]); int q = Integer.parseInt(ar[2]); int[][] dag = new int[n][n]; for (int i = 0; i < dag.length; i++) { for (int j = 0; j < dag[i].length; j++) dag[i][j] = -1; } for (int i = 0; i < m; i++) { String mLine = scanner.nextLine(); String[] mParams = mLine.split(" "); dag[Integer.parseInt(mParams[0]) - 1][Integer.parseInt(mParams[1]) - 1] = 0; dag[Integer.parseInt(mParams[0]) - 1][Integer.parseInt(mParams[0]) - 1] = 0; dag[Integer.parseInt(mParams[1]) - 1][Integer.parseInt(mParams[1]) - 1] = 0; } for (int i = 0; i < q; i++) { String qLine = scanner.nextLine(); String[] qs = qLine.split(" "); int[] qParams = new int[qs.length]; for (int j = 0; j < qs.length; j++) { qParams[j] = Integer.parseInt(qs[j]); } if (qParams[0] == 1) { setQOne(dag, qParams[1] - 1, qParams[2]); } if (qParams[0] == 2) { setQTwo(dag, qParams[1] - 1, qParams[2]); } if (qParams[0] == 3) { int res = dag[qParams[1] - 1][qParams[1] - 1]; System.out.println(res != -1 ? res : 0); } } } private static void setQTwo(int[][] dag, int qParams1, int qParams2) { for (int j = 0; j < dag[qParams1].length; j++) { if (dag[qParams1][j] > qParams2) { dag[qParams1][j] = qParams2; if (j == qParams1) continue; setQTwo(dag, j, qParams2); } } } private static void setQOne(int[][] dag, int qParams1, int qParams2) { for (int j = 0; j < dag[qParams1].length; j++) { if (dag[qParams1][j] != -1) { dag[qParams1][j] = qParams2; if (j == qParams1) continue; setQOne(dag, j, qParams2); } } }
Seems like cookies are disabled on this browser, please enable them to open this website
DAG Queries
You are viewing a single comment's thread. Return to all comments →
I can't seem to find the source of my error, if someone can help please, my tests succeed in the IDE but fail here