제출 #1290083

#제출 시각아이디문제언어결과실행 시간메모리
1290083nguyengiabach1201관광 (NOI14_sightseeing)C++20
0 / 25
1776 ms178124 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 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;

    set<array<int, 2>, cmp> pq;
    pq.insert({1, INF}), ans[1] = INF;

    while (!pq.empty())
    {
        // int u = pq.top()[0], val = pq.top()[1];
        // pq.pop();

        int u = (*pq.begin())[0], val = (*pq.begin())[1];
        pq.erase(pq.begin());

        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])
                pq.erase({v, ans[v]}), ans[v] = min(val, w), pq.insert({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;
}

컴파일 시 표준 에러 (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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...