ํฐ์คํ ๋ฆฌ ๋ทฐ
๐ฉ๐ป๐ป ๋ฌธ์
โ๐ป ํ์ด
๐จ Go
// https://www.acmicpc.net/problem/11265
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)
graph := make([][]int, n)
for i := 0; i < n; i++ {
graph[i] = make([]int, n)
}
for i := 0; i < n; i++ {
for j := 0; j < n; j++ {
fmt.Fscanf(reader, "%d ", &graph[i][j])
}
}
graph = floydWarshall(graph)
for i := 0; i < m; i++ {
var a, b, c int
fmt.Fscanln(reader, &a, &b, &c)
if graph[a-1][b-1] <= c {
fmt.Fprintln(writer, "Enjoy other party")
} else {
fmt.Fprintln(writer, "Stay here")
}
}
}
func floydWarshall(graph [][]int) [][]int {
for i := 0; i < len(graph); i++ { // j->k ๊ฒฝ๋ก๋ณด๋ค j->i->k ๊ฒฝ๋ก๊ฐ ๋น ๋ฅธ ๊ฒฝ์ฐ ๊ฐฑ์
for j := 0; j < len(graph); j++ {
for k := 0; k < len(graph); k++ {
if graph[j][i]+graph[i][k] < graph[j][k] {
graph[j][k] = graph[j][i] + graph[i][k]
}
}
}
}
return graph
}
๐จ Python3
# https://www.acmicpc.net/problem/11265
import sys
def floyd_warshall(graph):
for i in range(len(graph)):
for j in range(len(graph)):
for k in range(len(graph)):
if graph[j][i] + graph[i][k] < graph[j][k]:
graph[j][k] = graph[j][i] + graph[i][k]
return graph
if __name__ == "__main__":
n, m = list(map(int, sys.stdin.readline().split()))
graph = []
for i in range(n):
graph.append(list(map(int, sys.stdin.readline().split())))
graph = floyd_warshall(graph)
for i in range(m):
a, b, c = list(map(int, sys.stdin.readline().split()))
if graph[a-1][b-1] <= c:
print("Enjoy other party")
else:
print("Stay here")
728x90
'dev > algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
BOJ / 11719๋ฒ / ๊ทธ๋๋ก ์ถ๋ ฅํ๊ธฐ 2 [Go][Python3] (0) | 2021.01.07 |
---|---|
BOJ / 18243๋ฒ / Small World Network [Go][Python3] (0) | 2021.01.06 |
BOJ / 11403๋ฒ / ๊ฒฝ๋ก ์ฐพ๊ธฐ [Go][Python3] (0) | 2021.01.04 |
BOJ / 2178๋ฒ / ๋ฏธ๋ก ํ์ [Go][Python3] (0) | 2021.01.03 |
BOJ / 9372๋ฒ / ์๊ทผ์ด์ ์ฌํ [Go][Python3] (0) | 2021.01.02 |
๋๊ธ
๊ธ ๋ณด๊ดํจ
์ต๊ทผ์ ๋ฌ๋ฆฐ ๋๊ธ
TAG
- MongoDB
- AWS
- ๋ธ๋ฃจํธํฌ์ค
- Golang
- ํด์๋งต
- BFS
- ๋ฐ๋
- ๋งฅ๋ถ ์ ๊ทธ๋ ์ด๋
- python3
- ํ
- Macbook pro 2012 mid 13
- ๋ถํ ์ ๋ณต
- ballet
- dfs
- ๋ชฝ๊ณ ๋๋น
- ์๊ณ ๋ฆฌ์ฆ
- java
- ์๊ฐ๊ต์ฒด
- BOJ
- baekjoon
- Algorithm
- dp
- ํ๋ก์ด๋์์ฌ
- ์คํ
- go
- ์ด๋ถํ์
- ๋ฐฑ์ค
- ๋งฅ๋ถํ๋ก
- ๋งฅ๋ถ
- ์๋ฐ
- Total
- Today
- Yesterday