diff --git a/0x1D/solutions/1854.cpp b/0x1D/solutions/1854.cpp index 6c991660..8b066843 100644 --- a/0x1D/solutions/1854.cpp +++ b/0x1D/solutions/1854.cpp @@ -1,11 +1,36 @@ -// Authored by : BaaaaaaaaaaarkingDog +// Authored by : uhwan0723 // Co-authored by : - -// http://boj.kr/**************** +// http://boj.kr/2e7aad928479422d845f500c2c77609b #include using namespace std; +const int mn = 1e4+5; +int n, m, k; +vector d[mn]; +vector> adj[mn]; +priority_queue> pq; + int main(void){ ios::sync_with_stdio(0); cin.tie(0); - -} \ No newline at end of file + cout.tie(0); + cin >> n >> m >> k; + while(m--){ + int u, v, w; + cin >> u >> v >> w; + adj[u].push_back({w, v}); + } + pq.push({0, 1}); + while(!pq.empty()){ + int w = -pq.top().first, cur = pq.top().second; + pq.pop(); + if(d[cur].size() == k) continue; + d[cur].push_back(w); + for(auto nxt : adj[cur]) + pq.push({-(w + nxt.first), nxt.second}); + } + for(int i = 1; i <= n; ++i){ + if(d[i].size() < k) cout << -1 << '\n'; + else cout << d[i][k-1] << '\n'; + } +}