結果
問題 | No.483 マッチ並べ |
ユーザー | zimpha |
提出日時 | 2017-03-30 21:21:02 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 53 ms / 2,000 ms |
コード長 | 3,276 bytes |
コンパイル時間 | 1,969 ms |
コンパイル使用メモリ | 79,476 KB |
実行使用メモリ | 52,372 KB |
最終ジャッジ日時 | 2024-07-07 03:13:12 |
合計ジャッジ時間 | 6,031 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 49 ms
50,712 KB |
testcase_01 | AC | 48 ms
50,532 KB |
testcase_02 | AC | 49 ms
50,628 KB |
testcase_03 | AC | 49 ms
50,472 KB |
testcase_04 | AC | 49 ms
50,468 KB |
testcase_05 | AC | 48 ms
50,480 KB |
testcase_06 | AC | 48 ms
50,584 KB |
testcase_07 | AC | 48 ms
50,372 KB |
testcase_08 | AC | 48 ms
50,484 KB |
testcase_09 | AC | 47 ms
50,492 KB |
testcase_10 | AC | 48 ms
50,536 KB |
testcase_11 | AC | 48 ms
50,584 KB |
testcase_12 | AC | 49 ms
50,492 KB |
testcase_13 | AC | 48 ms
50,664 KB |
testcase_14 | AC | 48 ms
50,632 KB |
testcase_15 | AC | 49 ms
50,264 KB |
testcase_16 | AC | 50 ms
50,564 KB |
testcase_17 | AC | 49 ms
50,532 KB |
testcase_18 | AC | 48 ms
50,612 KB |
testcase_19 | AC | 48 ms
52,188 KB |
testcase_20 | AC | 47 ms
50,300 KB |
testcase_21 | AC | 48 ms
50,528 KB |
testcase_22 | AC | 47 ms
50,288 KB |
testcase_23 | AC | 49 ms
50,532 KB |
testcase_24 | AC | 47 ms
50,380 KB |
testcase_25 | AC | 48 ms
50,588 KB |
testcase_26 | AC | 49 ms
50,648 KB |
testcase_27 | AC | 51 ms
50,704 KB |
testcase_28 | AC | 50 ms
50,536 KB |
testcase_29 | AC | 50 ms
50,420 KB |
testcase_30 | AC | 51 ms
50,540 KB |
testcase_31 | AC | 50 ms
50,564 KB |
testcase_32 | AC | 51 ms
50,360 KB |
testcase_33 | AC | 50 ms
50,436 KB |
testcase_34 | AC | 49 ms
50,540 KB |
testcase_35 | AC | 49 ms
50,480 KB |
testcase_36 | AC | 49 ms
50,532 KB |
testcase_37 | AC | 49 ms
50,464 KB |
testcase_38 | AC | 49 ms
50,552 KB |
testcase_39 | AC | 50 ms
50,684 KB |
testcase_40 | AC | 49 ms
50,468 KB |
testcase_41 | AC | 48 ms
50,560 KB |
testcase_42 | AC | 49 ms
50,516 KB |
testcase_43 | AC | 49 ms
50,472 KB |
testcase_44 | AC | 49 ms
50,280 KB |
testcase_45 | AC | 50 ms
50,644 KB |
testcase_46 | AC | 48 ms
50,204 KB |
testcase_47 | AC | 49 ms
50,624 KB |
testcase_48 | AC | 51 ms
50,616 KB |
testcase_49 | AC | 50 ms
52,372 KB |
testcase_50 | AC | 50 ms
50,144 KB |
testcase_51 | AC | 49 ms
50,724 KB |
testcase_52 | AC | 53 ms
50,264 KB |
testcase_53 | AC | 49 ms
50,280 KB |
testcase_54 | AC | 48 ms
50,544 KB |
testcase_55 | AC | 47 ms
50,548 KB |
ソースコード
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Collection; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.StringTokenizer; import java.util.Queue; import java.io.BufferedReader; import java.util.LinkedList; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author Chiaki.Hoshinomori */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); Task483 solver = new Task483(); solver.solve(1, in, out); out.close(); } static class Task483 { public void solve(int testNumber, InputReader in, PrintWriter out) { int m = in.nextInt(); int n = 10000; int[] deg = new int[n]; ArrayList<Integer>[] graph = new ArrayList[n]; for (int i = 0; i < n; i++) { graph[i] = new ArrayList<>(); } for (int i = 0; i < m; i++) { int r0 = in.nextInt() - 1; int c0 = in.nextInt() - 1; int r1 = in.nextInt() - 1; int c1 = in.nextInt() - 1; int u = r0 * 100 + c0; int v = r1 * 100 + c1; graph[u].add(v); graph[v].add(u); deg[u]++; deg[v]++; } boolean[] mark = new boolean[n]; Queue<Integer> queue = new LinkedList<>(); for (int i = 0; i < n; i++) { if (deg[i] == 1) { queue.add(i); mark[i] = true; } } while (!queue.isEmpty()) { int u = queue.poll(); for (int v : graph[u]) { if (!mark[v] && --deg[v] == 1) { queue.add(v); mark[v] = true; } } } boolean valid = true; for (int i = 0; i < n; i++) { if (!mark[i] && deg[i] != 2 && deg[i] != 0) { valid = false; } } if (valid) out.println("YES"); else out.println("NO"); } } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } } }