結果
問題 | No.488 四角関係 |
ユーザー |
![]() |
提出日時 | 2020-12-18 14:19:39 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 234 ms / 5,000 ms |
コード長 | 1,396 bytes |
コンパイル時間 | 2,192 ms |
コンパイル使用メモリ | 79,336 KB |
実行使用メモリ | 45,224 KB |
最終ジャッジ日時 | 2024-09-21 09:08:41 |
合計ジャッジ時間 | 7,045 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 22 |
ソースコード
import java.util.*;public class Main {public static void main(String[] args) {Scanner sc = new Scanner(System.in);int n = sc.nextInt();int m = sc.nextInt();ArrayList<ArrayList<Integer>> graph = new ArrayList<>();ArrayList<HashSet<Integer>> exist = new ArrayList<>();for (int i = 0; i < n; i++) {graph.add(new ArrayList<>());exist.add(new HashSet<>());}for (int i = 0; i < m; i++) {int a = sc.nextInt();int b = sc.nextInt();graph.get(a).add(b);graph.get(b).add(a);exist.get(a).add(b);exist.get(b).add(a);}int ans = 0;for (int i = 0; i < n - 1; i++) {for (int j = i + 1; j < n; j++) {if (exist.get(i).contains(j)) {continue;}for (int a = 0; a < graph.get(i).size() - 1; a++) {for (int b = a + 1; b < graph.get(i).size(); b++) {if (exist.get(j).contains(graph.get(i).get(a)) && exist.get(j).contains(graph.get(i).get(b)) && !exist.get(graph.get(i).get(a)).contains(graph.get(i).get(b))) {ans++;}}}}}System.out.println(ans / 2);}}