|
|
вернуться в форумAC and WA#3 This my AC program. If I change one cycle, I get WA#3. WHY???? import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Solution { public static int[][] a; public static int[] d; public static int n; public static int top; public static int[] bol; public static void dfs(int v){ bol[v] = 1; int i; for(i = 0;i < n;i ++){ if(a[v][i] == 1){ a[v][i] = 0; dfs(i); } } d[top] = v; top ++; } public static void solve()throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(in.readLine()); n = Integer.parseInt(st.nextToken()); int m = Integer.parseInt(st.nextToken()); m --; a = new int[n][n]; d = new int[n * n + 1]; bol = new int[n]; top = 0; int i, j; int res = 0; for(i = 0;i < n;i ++){ st = new StringTokenizer(in.readLine()); for(j = 0;j < n;j ++){ a[i][j] = 1 - Integer.parseInt(st.nextToken()); if(i == j)a[i][i] = 0; res += a[i][j]; } } dfs(m); for(i = top - 1;i > 0;i --){ System.out.println((d[i] + 1) + " " + (d[i - 1] + 1)); } } public static void main(String[] args){ new Thread(){ public void run(){ try{ solve(); }catch(Exception e){ } } }.start(); } } This cycle. for(i = top - 1;i > 0;i --){ System.out.println((d[i] + 1) + " " + (d[i - 1] + 1)); } change to: for(i = 0;i < top - 1;i ++){ System.out.println((d[i] + 1) + " " + (d[i + 1] + 1)); } Re: AC and WA#3 had the same problem. Test #3. Bad: for (int i=0; i<ResultSize-1; ++i) printf("%d %d\n", Result[i]+1, Result[i+1]+1); Good: int i=ResultSize; while (i-->1) printf("%d %d\n", Result[i]+1, Result[i-1]+1); Changed bad to good and got AC. Admins, please check test #3. Re: AC and WA#3 There is such sentence in the problem statement: "One can pass through the channel only in one direction". That means the adjacency matrix is not symmetric and when you output the answer in reverse order, you may cross some channels such that channel (i,j) exists but (j,i) does not. Re: AC and WA#3 you cannot post code here!!!!! |
|
|