Skip to content

Commit 8fbd0f3

Browse files
committed
codeforce round 575
1 parent 97b6747 commit 8fbd0f3

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"files.associations": {
3+
"queue": "cpp",
4+
"utility": "cpp"
5+
}
6+
}

Codeforces/Codeforces Round/575/F.cpp

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#include <iostream>
2+
#include <algorithm>
3+
#include <queue>
4+
#include <vector>
5+
6+
using namespace std;
7+
8+
typedef long long ll;
9+
typedef pair<int, int> pr;
10+
11+
priority_queue<ll> ans;
12+
int n, m, k;
13+
vector<pr> graph[200002];
14+
15+
void dijkstra(int start)
16+
{
17+
int times = k + 1;
18+
priority_queue<pair<ll, int> > pq;
19+
vector<ll> dist(n + 1, -1);
20+
21+
pq.push({ 0, start });
22+
dist[start] = 0;
23+
24+
while(!pq.empty() && times)
25+
{
26+
ll d = -pq.top().first;
27+
int here = pq.top().second;
28+
pq.pop();
29+
30+
if(d > dist[here]) continue;
31+
times--;
32+
33+
if(here > start)
34+
{
35+
ans.push(d);
36+
if(ans.size() > k) ans.pop();
37+
}
38+
39+
for(pr edge : graph[here])
40+
{
41+
int next = edge.first;
42+
ll newDist = d + edge.second;
43+
44+
if(dist[next] == -1 || dist[next] > newDist)
45+
{
46+
dist[next] = newDist;
47+
pq.push({ -newDist, next });
48+
}
49+
}
50+
}
51+
}
52+
53+
int main()
54+
{
55+
ios::sync_with_stdio(false);
56+
cin.tie(NULL);
57+
58+
cin >> n >> m >> k;
59+
for(int i = 0; i < m; i++)
60+
{
61+
int x, y, w;
62+
cin >> x >> y >> w;
63+
graph[x].push_back({ y, w });
64+
graph[y].push_back({ x, w });
65+
}
66+
67+
for(int i = 1; i <= n; i++) dijkstra(i);
68+
69+
cout << ans.top() << '\n';
70+
}

0 commit comments

Comments
 (0)