ํฐ์คํ ๋ฆฌ ๋ทฐ
dev/algorithm
BOJ / 2422๋ฒ / ํ์ค์ ์ด ์ดํ๋ฆฌ์์ ๊ฐ์ ์์ด์คํฌ๋ฆผ์ ์ฌ๋จน๋๋ฐ [Go][Python3]
crscnt 2021. 1. 26. 21:00๐ฉ๐ป๐ป ๋ฌธ์
โ๐ป ํ์ด
๐จ Go
// https://www.acmicpc.net/problem/2422
package main
import (
"bufio"
"fmt"
"os"
)
func main() {
reader := bufio.NewReader(os.Stdin)
writer := bufio.NewWriter(os.Stdout)
defer writer.Flush()
var n, m int
fmt.Fscanln(reader, &n, &m)
var badCombination = make([][]bool, n)
for i := 0; i < n; i++ {
badCombination[i] = make([]bool, n)
}
for i := 0; i < m; i++ {
var iceOne, iceTwo int
fmt.Fscanln(reader, &iceOne, &iceTwo)
badCombination[iceOne-1][iceTwo-1] = true
badCombination[iceTwo-1][iceOne-1] = true
}
fmt.Fprintln(writer, getCountOfGoodCombination(badCombination))
}
func getCountOfGoodCombination(badCombination [][]bool) (count int) {
for i := 0; i < len(badCombination)-2; i++ {
for j := i + 1; j < len(badCombination)-1; j++ {
if badCombination[i][j] {
continue
}
for k := j + 1; k < len(badCombination); k++ {
if badCombination[i][k] || badCombination[j][k] {
continue
}
count++
}
}
}
return
}
๐จ Python3
# https://www.acmicpc.net/problem/2422
import sys
def get_count_of_good_combination(bad_combination):
count = 0
for i in range(len(bad_combination)-2):
for j in range(i+1, len(bad_combination)-1):
if bad_combination[i][j]:
continue
for k in range(j+1, len(bad_combination)):
if bad_combination[i][k] or bad_combination[j][k]:
continue
count += 1
return count
if __name__ == "__main__":
n, m = list(map(int, sys.stdin.readline().split()))
bad_combination = [[False for j in range(n)] for i in range(n)]
for i in range(m):
ice_one, ice_two = list(map(int, sys.stdin.readline().split()))
bad_combination[ice_one-1][ice_two-1] = True
bad_combination[ice_two-1][ice_one-1] = True
print(get_count_of_good_combination(bad_combination))
728x90
'dev > algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
BOJ / 2635๋ฒ / ์ ์ด์ด๊ฐ๊ธฐ [Go][Python3] (0) | 2021.01.28 |
---|---|
BOJ / 14916๋ฒ / ๊ฑฐ์ค๋ฆ ๋ [Go][Python3] (0) | 2021.01.27 |
BOJ / 1145๋ฒ / ์ ์ด๋ ๋๋ถ๋ถ์ ๋ฐฐ์ [Go][Python3] (0) | 2021.01.25 |
BOJ / 1969๋ฒ / DNA [Go][Python3] (0) | 2021.01.24 |
BOJ / 2503๋ฒ / ์ซ์ ์ผ๊ตฌ [Go][Python3] (0) | 2021.01.23 |
๋๊ธ
๊ธ ๋ณด๊ดํจ
์ต๊ทผ์ ๋ฌ๋ฆฐ ๋๊ธ
TAG
- ๋งฅ๋ถ ์ ๊ทธ๋ ์ด๋
- ๋งฅ๋ถ
- ๋ฐ๋
- ์๋ฐ
- dfs
- ballet
- BOJ
- ๋ฐฑ์ค
- MongoDB
- AWS
- ๋งฅ๋ถํ๋ก
- ์คํ
- Algorithm
- ์๊ฐ๊ต์ฒด
- ๋ถํ ์ ๋ณต
- ๋ชฝ๊ณ ๋๋น
- ์ด๋ถํ์
- python3
- ํ๋ก์ด๋์์ฌ
- baekjoon
- Macbook pro 2012 mid 13
- ํด์๋งต
- BFS
- dp
- java
- go
- ์๊ณ ๋ฆฌ์ฆ
- ๋ธ๋ฃจํธํฌ์ค
- Golang
- ํ
- Total
- Today
- Yesterday