結果
問題 | No.488 四角関係 |
ユーザー |
![]() |
提出日時 | 2019-12-19 14:29:41 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 104 ms / 5,000 ms |
コード長 | 1,703 bytes |
コンパイル時間 | 1,978 ms |
コンパイル使用メモリ | 78,124 KB |
実行使用メモリ | 52,700 KB |
最終ジャッジ日時 | 2024-07-07 01:09:30 |
合計ジャッジ時間 | 4,520 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 22 |
ソースコード
import java.util.*; import java.io.*; public class Main { static HashSet<Integer>[] graph; static int n; public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] first = br.readLine().split(" ", 2); int n = Integer.parseInt(first[0]); int m = Integer.parseInt(first[1]); graph = new HashSet[n]; for (int i = 0; i < n; i++) { graph[i] = new HashSet<Integer>(); } for (int i = 0; i < m; i++) { String[] line = br.readLine().split(" ", 2); int a = Integer.parseInt(line[0]); int b = Integer.parseInt(line[1]); graph[a].add(b); graph[b].add(a); } int count = 0; for (int i = 0; i < n; i++) { if (graph[i].size() < 2) { continue; } for (int x : graph[i]) { for (int y : graph[i]) { if (x >= y) { continue; } if (graph[x].contains(y)) { continue; } count += getCount(x, y, i); } } } System.out.println(count / 4); } static int getCount(int a, int b, int except) { int count = 0; for (int i = 0; i < graph.length; i++) { if (i == except) { continue; } if (graph[i].contains(a) && graph[i].contains(b) && !graph[i].contains(except)) { count++; } } return count; } }