fork(1) download
  1.  
  2. import java.util.ArrayList;
  3. import java.util.Scanner;
  4.  
  5. public class Main {
  6.  
  7. final static int SIZE=110;
  8.  
  9. static ArrayList<ArrayList<Integer>> list=new ArrayList();
  10. static ArrayList<Integer> list1=new ArrayList();
  11. static int vis[]=new int[SIZE], curr;
  12. static int mat[][]=new int[SIZE][SIZE];
  13.  
  14. public static void dfs(int node) {
  15.  
  16. vis[node]=1;
  17. list1.add(node);
  18. int l=list.get(node).size();
  19. int i,v;
  20. for(i=0;i<l;i++) {
  21.  
  22. v=list.get(node).get(i);
  23. if(vis[v]==0) {
  24.  
  25. vis[v]=1;
  26. dfs(v);
  27. }
  28. }
  29. }
  30.  
  31. static void dfs1(int node) {
  32.  
  33. vis[node]=1;
  34. int i,u,l=list.get(node).size();
  35. for(i=0;i<l;i++) {
  36.  
  37. u=list.get(node).get(i);
  38. if(vis[u]==0 && u!=curr) {
  39.  
  40. vis[u]=1;
  41. dfs1(u);
  42. }
  43. }
  44. }
  45.  
  46. public static void main(String[] args) {
  47.  
  48. Scanner sc=new Scanner(System.in);
  49.  
  50. int t=sc.nextInt(),n;
  51. int i,j,v,cnt,x,y,cs=1;
  52. char ch;
  53. while(t-->0) {
  54.  
  55. n=sc.nextInt();
  56. for(i=0;i<n;i++) {
  57.  
  58. ArrayList<Integer> tmpList=new ArrayList();
  59. vis[i]=0;
  60. for(j=0;j<n;j++) {
  61.  
  62. v=sc.nextInt();
  63. if(v==1)
  64. tmpList.add(j);
  65. mat[i][j]=0;
  66. }
  67. list.add(tmpList);
  68. }
  69.  
  70. dfs(0);
  71.  
  72. for(i=0;i<list1.size();i++) {
  73.  
  74. for(j=0;j<list1.size();j++)
  75. vis[list1.get(j)]=0;
  76.  
  77. curr=list1.get(i);
  78. if(curr!=0)
  79. dfs1(0);
  80.  
  81. for(j=0;j<list1.size();j++) {
  82.  
  83. if(vis[list1.get(j)]==0)
  84. mat[curr][list1.get(j)]=1;
  85. }
  86. }
  87. System.out.println("Case " + cs++ + ":");
  88. for(i=0;i<2*n+1;i++) {
  89.  
  90. for(j=0;j<2*n+1;j++) {
  91.  
  92. if(i%2==0) {
  93.  
  94. if(j==0||j==2*n) {
  95.  
  96. System.out.print("+");
  97. }
  98. else {
  99.  
  100. System.out.print("-");
  101. }
  102. }
  103. else {
  104.  
  105. if(j%2==0) {
  106.  
  107. System.out.print("|");
  108. }
  109. else {
  110.  
  111. x=i/2;
  112. y=j/2;
  113. ch=mat[x][y]==1?'Y':'N';
  114. System.out.print(ch);
  115. }
  116. }
  117. }
  118. System.out.println("");
  119. }
  120. list1.clear();
  121. list.clear();
  122. }
  123. }
  124. }
  125.  
Runtime error #stdin #stdout #stderr 0.06s 4386816KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Exception in thread "main" java.util.NoSuchElementException
	at java.util.Scanner.throwFor(Scanner.java:862)
	at java.util.Scanner.next(Scanner.java:1485)
	at java.util.Scanner.nextInt(Scanner.java:2117)
	at java.util.Scanner.nextInt(Scanner.java:2076)
	at Main.main(Main.java:50)