結果

問題 No.488 四角関係
ユーザー tsuchinagatsuchinaga
提出日時 2019-04-23 08:25:57
言語 Go
(1.22.1)
結果
AC  
実行時間 150 ms / 5,000 ms
コード長 1,369 bytes
コンパイル時間 15,757 ms
コンパイル使用メモリ 228,352 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-21 00:33:07
合計ジャッジ時間 16,855 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 8 ms
6,812 KB
testcase_02 AC 3 ms
6,944 KB
testcase_03 AC 3 ms
6,940 KB
testcase_04 AC 4 ms
6,940 KB
testcase_05 AC 10 ms
6,940 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 36 ms
6,944 KB
testcase_08 AC 150 ms
6,944 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 3 ms
6,940 KB
testcase_13 AC 1 ms
6,940 KB
testcase_14 AC 1 ms
6,940 KB
testcase_15 AC 1 ms
6,944 KB
testcase_16 AC 1 ms
6,940 KB
testcase_17 AC 1 ms
6,940 KB
testcase_18 AC 1 ms
6,940 KB
testcase_19 AC 1 ms
6,944 KB
testcase_20 AC 2 ms
6,944 KB
testcase_21 AC 1 ms
6,944 KB
testcase_22 AC 2 ms
6,944 KB
testcase_23 AC 1 ms
6,940 KB
testcase_24 AC 1 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	var n, m int
	_, _ = fmt.Scan(&n, &m)

	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	paths := make([][]int, n)
	for i := 0; i < m; i++ {
		sc.Scan()
		a, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		b, _ := strconv.Atoi(sc.Text())

		paths[a] = append(paths[a], b)
		paths[b] = append(paths[b], a)
	}

	// fmt.Println(paths)

	ans := 0
	for start := 0; start < n; start++ {
		// fmt.Println(start)

		for _, n1 := range paths[start] {
			// fmt.Println(start, n1)

			for _, n2 := range paths[n1] {
				// fmt.Println(start, n1, n2)

				if start == n2 {
					continue
				}

				no2 := false
				cnt2 := 0
				for _, n3 := range paths[n2] {
					// fmt.Println(start, n1, n2, n3)

					if n1 == n3 {
						continue
					}

					if start == n3 {
						no2 = true
						break
					}

					no3 := false
					cnt3 := 0
					for _, end := range paths[n3] {
						// fmt.Println(start, n1, n2, n3, end)

						if end == n2 {
							continue
						}

						if end == n1 {
							no3 = true
							break
						}

						if start == end {
							// fmt.Println("add cnt3")
							cnt3++
						}
					}

					if !no3 {
						// fmt.Println("add cnt2")
						cnt2 += cnt3
					}
				}

				if !no2 {
					// fmt.Println("add ans")
					ans += cnt2
				}
			}
		}
	}

	fmt.Println(ans / 8)
}
0