제출 #1261015

#제출 시각아이디문제언어결과실행 시간메모리
1261015vominhhuy123관광 (NOI14_sightseeing)C++20
15 / 25
1813 ms104648 KiB
#include <bits/stdc++.h>
#define fto(i, a, b) for (int i = (a); i <= (b); ++i)
#define fdto(i, b, a) for (int i = (b); i >= (a); --i)
#define N 500005
#define mod 1000000007

using namespace std;

int n, m, k, ans[N], p[N], sz[N];
vector<pair<int, int>> adj[N], edge[N];

int root(int u) {
    return p[u] != u ? p[u] = root(p[u]) : u;
}

bool join(int u, int v) {
    u = root(u), v = root(v);
    if (u == v) return false;
    if (sz[v] > sz[u]) swap(u, v);
    sz[u] += sz[v];
    p[v] = u;
    return true;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    if (fopen("test.inp", "r")) {
        freopen("test.inp", "r", stdin);
        freopen("test.out", "w", stdout);
    }
    cin >> n >> m >> k;
    fto(i, 1, n) p[i] = i, sz[i] = 1;
    fto(i, 1, m) {
        int u, v, w; cin >> u >> v >> w;
        edge[w].emplace_back(u, v);
    }
    fdto(w, 100000, 0) {
        for (pair<int, int> p : edge[w]) {
            int u = p.first, v = p.second;
            if (join(u, v)) {
                adj[u].emplace_back(v, w);
                adj[v].emplace_back(u, w);
            }
        }
    }
    fto(i, 1, n) ans[i] = -1;
    queue<int> q;
    q.push(1);
    ans[1] = N+1;
    while (q.size()) {
        int u = q.front(); q.pop();
        for (pair<int, int> &p : adj[u]) if (ans[p.first] == -1) {
            ans[p.first] = min(ans[u], p.second);
            q.push(p.first);
        }
    }
    while (k--) {
        int x; cin >> x;
        cout << ans[x] << '\n';
    }
}

컴파일 시 표준 에러 (stderr) 메시지

sightseeing.cpp: In function 'int main()':
sightseeing.cpp:28:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |         freopen("test.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sightseeing.cpp:29:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |         freopen("test.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...