結果
問題 | No.1605 Matrix Shape |
ユーザー |
![]() |
提出日時 | 2021-07-16 22:53:14 |
言語 | Java (openjdk 23) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,918 bytes |
コンパイル時間 | 2,549 ms |
コンパイル使用メモリ | 79,140 KB |
実行使用メモリ | 117,652 KB |
最終ジャッジ日時 | 2024-07-06 10:25:39 |
合計ジャッジ時間 | 20,748 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 RE * 1 |
other | AC * 17 WA * 1 RE * 16 |
ソースコード
import java.io.BufferedReader;import java.io.InputStreamReader;import java.util.ArrayList;import java.util.HashSet;import java.util.List;import java.util.Set;public class Main {static int n;static List<Set<Hen>> list;public static void main(String[] args) throws Exception {BufferedReader br = new BufferedReader(new InputStreamReader(System.in));n = Integer.parseInt(br.readLine());int m = 200000;list = new ArrayList<>(m);for (int i = 0; i < m; i++) {list.add(new HashSet<>());}int[] in = new int[m];int[] out = new int[m];for (int i = 0; i < n; i++) {String[] sa = br.readLine().split(" ");Hen h = new Hen();h.a = Integer.parseInt(sa[0]) - 1;h.b = Integer.parseInt(sa[1]) - 1;if (h.a != h.b) {list.get(h.a).add(h);out[h.a]++;in[h.b]++;}}br.close();int s = -1;int t = -1;for (int i = 0; i < m; i++) {if (in[i] != out[i]) {if (Math.abs(in[i] - out[i]) > 1) {System.out.println(0);return;}if (in[i] + 1 == out[i]) {if (s == -1) {s = i;} else {System.out.println(0);return;}} else {if (t == -1) {t = i;} else {System.out.println(0);return;}}}}if (s == -1 && t == -1) {int ans = 0;for (int i = 0; i < m; i++) {if (!list.get(i).isEmpty()) {ans++;}}System.out.println(ans);throw new Exception();// } else if (s == -1) {// int ans = 0;// for (int i = 0; i < m; i++) {// if (out[i] > 0) {// ans++;// }// }// System.out.println(ans);// throw new Exception();// } else if (t == -1) {// int ans = 0;// for (int i = 0; i < m; i++) {// if (in[i] > 0) {// ans++;// }// }// System.out.println(ans);// throw new Exception();} else {System.out.println(1);}}static class Hen {int a, b;}}