Submission #335788

#TimeUsernameProblemLanguageResultExecution timeMemory
335788AgnimandurConnecting Supertrees (IOI20_supertrees)Java
0 / 100
95 ms8624 KiB
import java.util.*; public class supertrees { public int construct(int[][] p) { int N = p.length; for (int[] i: p) { for (int j: i) { if (j==3) return 0; } } int[][] ans = new int[N][N]; boolean[] vis = new boolean[N]; boolean[] vis2 = new boolean[N]; ArrayDeque<Integer> bfs = new ArrayDeque<Integer>(); for (int r = 0; r < N; r++) { if (vis[r])continue; ArrayList<Integer> comp = new ArrayList<Integer>(); bfs.add(r); vis[r] = true; while (!bfs.isEmpty()) { int i = bfs.pollFirst(); comp.add(i); for (int j = 0; j < N; j++) { if (!vis[j] && p[i][j] > 0) { vis[j] = true; bfs.add(j); } } } for (int i: comp) { for (int j: comp) { if (p[i][j]==0) return 0; } } ArrayList<Integer> cyc = new ArrayList<Integer>(); for (int c: comp) { if (vis2[c])continue; cyc.add(c); vis2[c] = true; bfs.add(c); ArrayList<Integer> sub = new ArrayList<Integer>(); while (!bfs.isEmpty()) { int i = bfs.pollFirst(); sub.add(i); for (int j: comp) { if (!vis2[j] && p[i][j]==1) { vis2[j] = true; bfs.add(j); } } } for (int ind = 1; ind < sub.size(); ind++) { int i = sub.get(ind-1); int j = sub.get(ind); ans[i][j] = 1; ans[j][i] = 1; } for (int i: sub) { for (int j: sub) { if (p[i][j]==2) return 0; } } } for (int ind = 0; ind < cyc.size(); ind++) { int i = cyc.get(ind); int j = cyc.get((ind+1)%cyc.size()); ans[i][j] = 1; ans[j][i] = 1; } } grader.build(ans); return 1; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...