Submission #57569
Source Code Expand
import java.util.Arrays; import java.util.BitSet; import java.util.Scanner; public class Main { static Scanner sc = new Scanner(System.in); static int N, M; static long E; static StringBuilder out = new StringBuilder(); static BitSet[] g; public static void main(String[] args) { N = sc.nextInt(); M = sc.nextInt(); E = ((long) N) * (N - 1) / 2; if (E - M > N - 1) { for (int i = 0; i < M; ++i) { out.append("no\n"); } System.out.print(out); return; } g = new BitSet[N]; for (int i = 0; i < N; ++i) { g[i] = new BitSet(N); g[i].set(0, N); g[i].clear(i); } for (int i = 0; i < M; ++i) { int S = Integer.parseInt(sc.next()) - 1; int T = Integer.parseInt(sc.next()) - 1; g[T].set(S, !g[S].get(T)); g[S].set(T, !g[S].get(T)); if (g[S].get(T)) { ++E; } else { --E; } out.append(calc() ? "yes\n" : "no\n"); } System.out.print(out); } static boolean calc() { if (E > N - 1) return false; if (E <= 2) return true; boolean[] used = new boolean[N]; for (int i = 0; i < N; ++i) { if (used[i]) continue; used[i] = true; if (!dfs(i, -1, used)) { return false; } } return true; } static boolean dfs(int pos, int from, boolean[] used) { for (int i = g[pos].nextSetBit(0); i >= 0; i = g[pos].nextSetBit(i + 1)) { if (i == from) continue; if (used[i]) return false; used[i] = true; if (!dfs(i, pos, used)) { return false; } } return true; } }
Submission Info
Submission Time | |
---|---|
Task | C - 森ですか? |
User | tomerun |
Language | Java (OpenJDK 1.7.0) |
Score | 100 |
Code Size | 1544 Byte |
Status | AC |
Exec Time | 1476 ms |
Memory | 50768 KB |
Judge Result
Set Name | Easy | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 50 / 50 | 50 / 50 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Easy | easy_01_00.txt, easy_01_01.txt, easy_01_02.txt, easy_01_03.txt, easy_01_04.txt, easy_02_00.txt, easy_02_01.txt, easy_02_02.txt, easy_02_03.txt, easy_02_04.txt, easy_03_00.txt, easy_03_01.txt, easy_03_02.txt, easy_03_03.txt, easy_03_04.txt, easy_04_00.txt, easy_04_01.txt, easy_04_02.txt, easy_04_03.txt, easy_04_04.txt, easy_05_00.txt, easy_05_01.txt, easy_05_02.txt, easy_05_03.txt, easy_05_04.txt, easy_06_00.txt, easy_06_01.txt, easy_06_02.txt, easy_06_03.txt, easy_06_04.txt, easy_07_00.txt, easy_07_01.txt, easy_07_02.txt, easy_07_03.txt, easy_07_04.txt, easy_08_00.txt, easy_08_01.txt |
All | easy_01_00.txt, easy_01_01.txt, easy_01_02.txt, easy_01_03.txt, easy_01_04.txt, easy_02_00.txt, easy_02_01.txt, easy_02_02.txt, easy_02_03.txt, easy_02_04.txt, easy_03_00.txt, easy_03_01.txt, easy_03_02.txt, easy_03_03.txt, easy_03_04.txt, easy_04_00.txt, easy_04_01.txt, easy_04_02.txt, easy_04_03.txt, easy_04_04.txt, easy_05_00.txt, easy_05_01.txt, easy_05_02.txt, easy_05_03.txt, easy_05_04.txt, easy_06_00.txt, easy_06_01.txt, easy_06_02.txt, easy_06_03.txt, easy_06_04.txt, easy_07_00.txt, easy_07_01.txt, easy_07_02.txt, easy_07_03.txt, easy_07_04.txt, easy_08_00.txt, easy_08_01.txt, hard_01_00.txt, hard_01_01.txt, hard_01_02.txt, hard_01_03.txt, hard_01_04.txt, hard_02_00.txt, hard_02_01.txt, hard_02_02.txt, hard_02_03.txt, hard_02_04.txt, hard_03_00.txt, hard_03_01.txt, hard_03_02.txt, hard_03_03.txt, hard_03_04.txt, hard_04_00.txt, hard_04_01.txt, hard_04_02.txt, hard_04_03.txt, hard_04_04.txt, hard_05_00.txt, hard_05_01.txt, hard_05_02.txt, hard_05_03.txt, hard_05_04.txt, hard_06_00.txt, hard_06_01.txt, hard_06_02.txt, hard_06_03.txt, hard_06_04.txt, hard_07_00.txt, hard_07_01.txt, hard_07_02.txt, hard_07_03.txt, hard_07_04.txt, hard_08_00.txt, hard_08_01.txt, hard_09_00.txt, hard_09_01.txt, hard_09_02.txt, hard_09_03.txt, hard_09_04.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
easy_01_00.txt | AC | 462 ms | 20536 KB |
easy_01_01.txt | AC | 465 ms | 20664 KB |
easy_01_02.txt | AC | 477 ms | 20912 KB |
easy_01_03.txt | AC | 471 ms | 20652 KB |
easy_01_04.txt | AC | 494 ms | 20760 KB |
easy_02_00.txt | AC | 439 ms | 20168 KB |
easy_02_01.txt | AC | 445 ms | 20252 KB |
easy_02_02.txt | AC | 450 ms | 20264 KB |
easy_02_03.txt | AC | 458 ms | 20268 KB |
easy_02_04.txt | AC | 451 ms | 20200 KB |
easy_03_00.txt | AC | 471 ms | 20700 KB |
easy_03_01.txt | AC | 461 ms | 20652 KB |
easy_03_02.txt | AC | 470 ms | 20640 KB |
easy_03_03.txt | AC | 508 ms | 20536 KB |
easy_03_04.txt | AC | 464 ms | 20552 KB |
easy_04_00.txt | AC | 433 ms | 20268 KB |
easy_04_01.txt | AC | 444 ms | 20280 KB |
easy_04_02.txt | AC | 487 ms | 20276 KB |
easy_04_03.txt | AC | 463 ms | 20148 KB |
easy_04_04.txt | AC | 454 ms | 20264 KB |
easy_05_00.txt | AC | 455 ms | 20644 KB |
easy_05_01.txt | AC | 516 ms | 20704 KB |
easy_05_02.txt | AC | 500 ms | 20648 KB |
easy_05_03.txt | AC | 461 ms | 20652 KB |
easy_05_04.txt | AC | 465 ms | 20632 KB |
easy_06_00.txt | AC | 461 ms | 20300 KB |
easy_06_01.txt | AC | 535 ms | 20328 KB |
easy_06_02.txt | AC | 446 ms | 20276 KB |
easy_06_03.txt | AC | 433 ms | 20196 KB |
easy_06_04.txt | AC | 444 ms | 20140 KB |
easy_07_00.txt | AC | 464 ms | 20528 KB |
easy_07_01.txt | AC | 451 ms | 20660 KB |
easy_07_02.txt | AC | 501 ms | 20580 KB |
easy_07_03.txt | AC | 469 ms | 20680 KB |
easy_07_04.txt | AC | 465 ms | 20648 KB |
easy_08_00.txt | AC | 464 ms | 20528 KB |
easy_08_01.txt | AC | 541 ms | 20640 KB |
hard_01_00.txt | AC | 970 ms | 46416 KB |
hard_01_01.txt | AC | 961 ms | 45588 KB |
hard_01_02.txt | AC | 963 ms | 47152 KB |
hard_01_03.txt | AC | 980 ms | 44976 KB |
hard_01_04.txt | AC | 915 ms | 43020 KB |
hard_02_00.txt | AC | 479 ms | 22828 KB |
hard_02_01.txt | AC | 1360 ms | 22960 KB |
hard_02_02.txt | AC | 556 ms | 22580 KB |
hard_02_03.txt | AC | 527 ms | 25696 KB |
hard_02_04.txt | AC | 519 ms | 23224 KB |
hard_03_00.txt | AC | 984 ms | 46684 KB |
hard_03_01.txt | AC | 1031 ms | 46240 KB |
hard_03_02.txt | AC | 955 ms | 41832 KB |
hard_03_03.txt | AC | 1002 ms | 46824 KB |
hard_03_04.txt | AC | 989 ms | 46940 KB |
hard_04_00.txt | AC | 950 ms | 46292 KB |
hard_04_01.txt | AC | 518 ms | 23480 KB |
hard_04_02.txt | AC | 875 ms | 46544 KB |
hard_04_03.txt | AC | 598 ms | 21424 KB |
hard_04_04.txt | AC | 817 ms | 44944 KB |
hard_05_00.txt | AC | 1056 ms | 46256 KB |
hard_05_01.txt | AC | 1476 ms | 49432 KB |
hard_05_02.txt | AC | 1318 ms | 46096 KB |
hard_05_03.txt | AC | 1118 ms | 46316 KB |
hard_05_04.txt | AC | 1102 ms | 46200 KB |
hard_06_00.txt | AC | 480 ms | 22836 KB |
hard_06_01.txt | AC | 485 ms | 22836 KB |
hard_06_02.txt | AC | 496 ms | 24120 KB |
hard_06_03.txt | AC | 901 ms | 46468 KB |
hard_06_04.txt | AC | 1114 ms | 46500 KB |
hard_07_00.txt | AC | 990 ms | 46932 KB |
hard_07_01.txt | AC | 1093 ms | 48176 KB |
hard_07_02.txt | AC | 1240 ms | 46720 KB |
hard_07_03.txt | AC | 1084 ms | 47908 KB |
hard_07_04.txt | AC | 1095 ms | 47800 KB |
hard_08_00.txt | AC | 985 ms | 46092 KB |
hard_08_01.txt | AC | 520 ms | 25996 KB |
hard_09_00.txt | AC | 1029 ms | 46220 KB |
hard_09_01.txt | AC | 999 ms | 47048 KB |
hard_09_02.txt | AC | 998 ms | 47660 KB |
hard_09_03.txt | AC | 1032 ms | 50768 KB |
hard_09_04.txt | AC | 1013 ms | 48600 KB |
sample1.txt | AC | 473 ms | 20132 KB |
sample2.txt | AC | 517 ms | 20232 KB |