#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define el '\n'
#define FNAME "tinhcldd"
#define ll long long
#define int long long
#define MOD (int)(1e9 + 7)
#define INF (ll)(1e18 + 1)
void setup()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
if (fopen(FNAME ".inp", "r"))
{
freopen(FNAME ".inp", "r", stdin);
freopen(FNAME ".out", "w", stdout);
}
return;
}
const int N = 5e5 + 5;
int n, m, q;
vector<array<int, 2>> adj[N];
int p[N], ans[N];
bool checked[N];
struct cmp
{
bool operator()(const array<int, 2> &a, const array<int, 2> &b) const
{
if (a[1] != b[1])
return a[1] < b[1];
return a[0] < b[0];
}
};
void dijkstra()
{
fill(ans, ans + N, -INF), fill(checked, checked + N, false);
priority_queue<array<int, 2>, vector<array<int, 2>>, cmp> pq;
pq.push({1, INF}), ans[1] = INF;
while (!pq.empty())
{
int u = pq.top()[0], val = pq.top()[1];
pq.pop();
if (checked[u])
continue;
// cerr << u << " " << val << " " << ans[u] << el;
checked[u] = true;
for (array<int, 2> e : adj[u])
{
int v = e[0], w = e[1];
if (!checked[v] && min(val, w) > ans[v])
ans[v] = min(val, w), pq.push({v, ans[v]});
}
}
}
void solve()
{
cin >> n >> m >> q;
for (int x, y, z, i = 1; i <= m; ++i)
cin >> x >> y >> z, adj[x].push_back({y, z}), adj[y].push_back({x, z});
for (int i = 1; i <= q; ++i)
cin >> p[i];
dijkstra();
for (int i = 1; i <= q; ++i)
cout << ans[p[i]] << el;
return;
}
signed main()
{
setup();
solve();
return 0;
}
Compilation message (stderr)
sightseeing.cpp: In function 'void setup()':
sightseeing.cpp:21:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
21 | freopen(FNAME ".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
sightseeing.cpp:22:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
22 | freopen(FNAME ".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |