| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1312767 | nguyengiabach1201 | Sightseeing (NOI14_sightseeing) | C++20 | 2583 ms | 306376 KiB |
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define el '\n'
#define FNAME ""
#define ll long long
#define MOD (int)(1e9 + 7)
#define INF (ll)(2e18 + 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);
}
}
const int N = 5e5 + 5;
int n, m, q;
struct Edge
{
int to;
ll weight;
};
vector<Edge> adj[N];
ll ans[N];
int p[N];
bool checked[N];
struct State
{
int u;
ll val;
bool operator<(const State &other) const
{
return val < other.val;
}
};
void dijkstra()
{
for (int i = 1; i <= n; ++i)
{
ans[i] = -1;
checked[i] = false;
}
priority_queue<State> pq;
pq.push({1, INF});
ans[1] = INF;
while (!pq.empty())
{
int u = pq.top().u;
ll val = pq.top().val;
pq.pop();
if (checked[u])
continue;
checked[u] = true;
for (auto &e : adj[u])
{
int v = e.to;
ll w = e.weight;
if (!checked[v])
{
ll next_val = min(val, w);
if (next_val > ans[v])
{
ans[v] = next_val;
pq.push({v, ans[v]});
}
}
}
}
}
void solve()
{
cin >> n >> m >> q;
for (int i = 0; i < m; ++i)
{
int x, y;
ll z;
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)
{
if (ans[p[i]] == -1)
cout << 0 << el;
else
cout << ans[p[i]] << el;
}
}
int 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... | ||||
