Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
batman
//'main' method must be in a class 'Rextester'. //openjdk version '11.0.5' import java.util.*; import java.lang.*; //import java.util.Stack; class Rextester { public static int batman(int a[][], int p) { int z; Stack<Integer> s = new Stack<>(); for(int i=0;i<p;i++) s.push(i); int x,y; while(s.size() > 1) { x=s.pop(); y=s.pop(); if(a[x][y]==1) s.push(y); else s.push(x); } if(s.empty()) return -1; z=s.pop(); // System.out.println(z); /* if(a[z][y]==1) z=y; if(a[z][x]==1) z=x;*/ for(int i=0;i<p;i++) { if( i!=z && ( (a[z][i] == 1) || a[i][z] == 0 ) ) return -1; } return z; } public static void main(String args[]) { Scanner sc=new Scanner(System.in); int p=sc.nextInt(); int a[][]=new int[p][p]; for(int i=0;i<p;i++) for(int j=0;j<p;j++) a[i][j]=sc.nextInt(); int answer=batman(a,p); System.out.println(answer); } }
run
|
edit
|
history
|
help
0
Check Input
First Unique Character in a String
Java # Bir Cumlenin uzunluğu
AllStar
Central Inteligence Agency
Instance fields are no overridden
stringkeyvalues
Main.java
Hi Hypotaneous
Rotate matrix clockwise