| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1312768 | nguyengiabach1201 | Sightseeing (NOI14_sightseeing) | C++20 | 2402 ms | 305128 KiB |
#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 MOD (ll)(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<ll, 2>> adj[N];
int p[N];
ll ans[N];
bool checked[N];
struct cmp
{
bool operator()(const array<ll, 2> &a, const array<ll, 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<ll, 2>, vector<array<ll, 2>>, cmp> pq;
pq.push({1, INF}), ans[1] = INF;
while (!pq.empty())
{
ll u = pq.top()[0], val = pq.top()[1];
pq.pop();
if (checked[u])
continue;
checked[u] = true;
for (auto &e : adj[u])
{
int v = (int)e[0];
ll w = e[1];
if (!checked[v] && min(val, w) > ans[v])
{
ans[v] = min(val, w);
pq.push({(ll)v, ans[v]});
}
}
}
}
void solve()
{
cin >> n >> m >> q;
for (int i = 1; i <= m; ++i)
{
int x, y;
ll z;
cin >> x >> y >> z;
adj[x].push_back({(ll)y, z});
adj[y].push_back({(ll)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)
| # | 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... | ||||
