Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

13-fnzksxl #64

Merged
merged 3 commits into from
Apr 10, 2024
Merged

13-fnzksxl #64

merged 3 commits into from
Apr 10, 2024

Conversation

fnzksxl
Copy link
Member

@fnzksxl fnzksxl commented Mar 20, 2024

๐Ÿ”— ๋ฌธ์ œ ๋งํฌ

์„œ๊ฐ•๊ทธ๋ผ์šด๋“œ

โœ”๏ธ ์†Œ์š”๋œ ์‹œ๊ฐ„

30๋ถ„ ๋ฏธ๋งŒ?

โœจ ์ˆ˜๋„ ์ฝ”๋“œ

๋ฏผ์„๋‹˜๊ป˜์„œ ๋‹ค์ต์ŠคํŠธ๋ผ ๋ฌธ์ œ ๋ง์”€ํ•˜์…”์„œ ๋จผ์ € ์ œ๊ฐ€ ์„ ์ˆ˜์ณ๋ดค์Šต๋‹ˆ๋‹ค. ๋ฌธ์ œ ์ด๋ฆ„๋ถ€ํ„ฐ ๊น”์Œˆํ•˜๊ธธ๋ž˜ ํ˜นํ•˜๊ณ  ๋“ค์–ด๊ฐ€๋ฒ„๋ ธ์ง€ ๋ญ์—์š” ํ•˜ํ•˜ใ…ใ……ํ•˜

๋ฌธ์ œ๋ฅผ ์ฝ์–ด๋ณด์‹œ๋ฉด ๊ธˆ๋ฐฉ ๋ˆˆ์น˜์ฑ„์‹œ๊ฒ ์ง€๋งŒ, ๋‹ค์ต์ŠคํŠธ๋ผ ๋ฌธ์ œ์ž…๋‹ˆ๋‹ค.
์–ด.. ๋„ˆ๋ฌด ๊ฐ„๋‹จํ•ด์„œ ๋”ฑํžˆ ์„ค๋ช…ํ• ๊ฒŒ ์—†๋„ค์š”.

node๊ฐ€ N๊ฐœ๋งŒํผ ์žˆ์„ ๋•Œ, ๋‹ค์ต์ŠคํŠธ๋ผ ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ N๋ฒˆ ๋Œ๋ ค๋ด…๋‹ˆ๋‹ค.
๊ฐ๊ฐ์˜ ๋‹ค์ต์ŠคํŠธ๋ผ ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ๋Œ๋ฆด ๋•Œ, ๋ฆฌํ„ด๋ฐ›์€ distance ๋‚ด๋ถ€ ๋ฐฐ์—ด์ด
M๋ณด๋‹ค ์ž‘์€ ์ˆซ์ž์ผ ๊ฒฝ์šฐ ๊ทธ ์ง€์—ญ์˜ ์•„์ดํ…œ ๊ฐœ์ˆ˜๋งŒํผ ๋”ํ•ด์ค๋‹ˆ๋‹ค.

๊ฐ๊ฐ์˜ ๊ฒฐ๊ณผ์— ๋Œ€ํ•ด์„œ ๊ฐ€์žฅ ํฐ ๊ฐ’์„ ๋ฆฌํ„ดํ•ด์ฃผ๋ฉด ์ •๋‹ต์ž…๋‹ˆ๋‹ค!

์ „์ฒด ์ฝ”๋“œ

import sys
from heapq import *

input = sys.stdin.readline

def dijkstra(graph, start):
    distance = [float('inf') for _ in graph]
    distance[start] = 0
    queue = []
    heappush(queue, [distance[start], start])

    while queue:
        cur_dist, cur_dest = heappop(queue)

        if distance[cur_dest] < cur_dist:
            continue

        for new_dest, new_dist in graph[cur_dest]:
            dist = cur_dist + new_dist
            if dist < distance[new_dest]:
                distance[new_dest] = dist
                heappush(queue, [dist, new_dest])

    return distance


items = []
N, M, R = map(int, input().split())

item_weight = list(map(int, input().split()))
graph = [[] for _ in range(N+1)]

for _ in range(R):
    start, end, weight = map(int, input().split())
    graph[start].append((end, weight))
    graph[end].append((start, weight))

for item in range(1, len(graph)):
    result = dijkstra(graph, item)
    can_get = 0
    for i in range(len(result)):
        if result[i] <= M:
            can_get += item_weight[i-1]
    items.append(can_get)

print(max(items))

๐Ÿ“š ์ƒˆ๋กญ๊ฒŒ ์•Œ๊ฒŒ๋œ ๋‚ด์šฉ

Copy link
Collaborator

@wkdghdwns199 wkdghdwns199 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ํƒœ์›๋‹˜ ์ฝ”๋“œ ํ•œ ๋ฒˆ ๋ณด๊ณ  ๋”ฐ๋ผํ•ด๋ณด๊ณ  ๋‹ค์ต์ŠคํŠธ๋ผ ์•Œ๊ณ ๋ฆฌ์ฆ˜ ๊ฒ€์ƒ‰ํ•ด์„œ ๋ดค๋Š”๋ฐ ๊ธฐ์–ต์ด ์•ˆ๋‚˜๊ณ  ์˜คํžˆ๋ ค ์–ด๋ ต๋„ค์š”.. ์‰ฌ์šด ์„ค๋ช… ์ฐพ์œผ๋Ÿฌ ๋– ๋‚˜๋ด…๋‹ˆ๋‹ค

import sys
from heapq import *
input = sys.stdin.readline

def dijkstra(graph, start):
    length = [float('inf') for _ in graph]
    length[start] = 0
    queue = []
    heappush(queue, [length[start], start])
    
    while queue:
        current_length, current_target = heappop(queue)

        if length[current_target] < current_length :
            continue
        
        for new_target, new_length in graph[current_target] :
            len = current_length + new_length
            if len < length[new_target]:
                length[new_target] = len
                heappush(queue, [len, new_target])
    return length

items = []
N,M,R = map(int, input().split())
T = list(map(int, input().split()))
graph = [[] for _ in range(N+1)]

for _ in range(R):
    start, end, weight = map(int, input().split())
    graph[start].append((end, weight))
    graph[end].append((start, weight))
    
for item in range(1, len(graph)) :
    result = dijkstra(graph, item)
    get = 0
    for i in range(len(result)):
        if result[i] <= M :
            get += T[i-1]
    items.append(get)

print(max(items))

@alstjr7437 alstjr7437 removed their request for review March 23, 2024 13:33
@SeongHoonC SeongHoonC removed their request for review April 3, 2024 14:59
@fnzksxl fnzksxl merged commit 67a75ed into main Apr 10, 2024
6 checks passed
@fnzksxl fnzksxl deleted the 13-fnzksxl branch April 10, 2024 09:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants