Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 |
Tags
- Python
- 수학
- 이분 탐색
- 2357
- SSAFY
- 트리
- 문자열
- 싸피
- 그래프
- 누적 합
- 애드 혹
- BFS
- 13164
- 그리디
- 브루트포스
- 정렬
- 슬라이딩 윈도우
- 플로이드-워셜
- DFS
- 정수론
- 에라토스테네스의 체
- DP
- 맵
- 투 포인터
- boj
- 해시 테이블
- 구현
- 세그먼트 트리
- 모던 JavaScript 튜토리얼
- JavaScript
Archives
- Today
- Total
흙금이네 블로그
[BOJ] 11265 - 끝나지 않는 파티 (Python, JavaScript) 본문
아이디어
플로이드-워셜 알고리즘으로 모든 파티장 간의 이동 시간을 구한다.
풀이 #1 (Python)
import sys
input = sys.stdin.readline
def solution():
N, M = map(int, input().split())
graph = []
for _ in range(N):
graph.append(list(map(int, input().split())))
for k in range(N):
for i in range(N):
for j in range(N):
if graph[i][k]+graph[k][j] < graph[i][j]:
graph[i][j] = graph[i][k]+graph[k][j]
for _ in range(M):
A, B, C = map(int, input().split())
if graph[A-1][B-1] <= C:
print('Enjoy other party')
else:
print('Stay here')
solution()
풀이 #2 (JavaScript)
const fs = require('fs');
const input = fs.readFileSync('/dev/stdin').toString().split('\n');
function solution() {
const [N, M] = input[0].split(' ').map(Number);
let graph = [];
for (let i=1; i<=N; i++) {
graph.push(input[i].split(' ').map(Number));
}
for (let k=0; k<N; k++) {
for (let i=0; i<N; i++) {
for (let j=0; j<N; j++) {
if (graph[i][k]+graph[k][j] < graph[i][j]) {
graph[i][j] = graph[i][k]+graph[k][j];
}
}
}
}
for (let i=N+1; i<=N+M; i++) {
const [A, B, C] = input[i].split(' ').map(Number);
if (graph[A-1][B-1] <= C) {
console.log('Enjoy other party');
}
else {
console.log('Stay here');
}
}
}
solution();
'알고리즘' 카테고리의 다른 글
[BOJ] 2208 - 보석 줍기 (Python, JavaScript) (0) | 2023.05.08 |
---|---|
[BOJ] 2412 - 암벽 등반 (Python, JavaScript) (0) | 2023.05.07 |
[BOJ] 22856 - 트리 순회 (Python, JavaScript) (0) | 2023.05.05 |
[BOJ] 1477 - 휴게소 세우기 (Python) (0) | 2023.05.04 |
[BOJ] 1270 - 전쟁 - 땅따먹기 (Python) (0) | 2023.05.03 |
Comments