제출 #565709

#제출 시각아이디문제언어결과실행 시간메모리
5657091zaid1Evacuation plan (IZhO18_plan)C++14
23 / 100
4083 ms76332 KiB
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
typedef long long ll;
const int M = 2e6 + 5, MOD = 1e9+7;
vector<pair<int, int>> node[M];
int dist[M], dist2[M], n, vis[M];
 
void dij1() {
    for (int i = 1; i <= n; i++) dist[i] = INT_MAX;
    priority_queue<pair<int, int>> q;
    int k;
    cin >> k;
    for (int i = 1; i <= k; i++) {
        int a; cin >> a;
        dist[a] = 0;
        q.push({0, a});
    }
 
    while (!q.empty()) {
        auto [new_dist, new_node] = q.top(); q.pop();
        new_dist = -new_dist;
        if (dist[new_node] < new_dist) continue;
        for (auto [n, d]:node[new_node]) {
            if (new_dist + d < dist[n]) {
                dist[n] = new_dist + d;
                q.push({-dist[n], n});
            }
        }
    }
}

int rec(int a, int b) {
    if (a == b) return dist[a];
    int mn = 0;
    for (auto [i,x]:node[a]) {
        if (!vis[i]) {
            vis[i] = 1;
            mn = max(mn, rec(i, b));
            vis[i] = 0;
        }
    }

    return min(mn, dist[a]);
}

signed main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    srand(time(0));
    
    int m;
    cin >> n >> m;

    map<pair<int, int>, bool> ok;
 
    for (int i = 1; i <= m; i++) {
        int a, b, c;
        cin >> a >> b >> c;
 
        node[a].push_back({b, c});
        node[b].push_back({a, c});
    }
 
    dij1();
 
    int t;
    cin >> t;

    if (t == 1) {
        int a, b;
        cin >> a >> b;
        vis[a] = 1;
        cout << rec(a, b) << endl;
        return 0;
    }
 
    while (t--) {
        int a, b;
        cin >> a >> b;
 
        cout << min(dist[a], dist[b]) << endl;
    }
 
    return 0;
}
 
/*
9 12
1 9 4
1 2 5
2 3 7
2 4 3
4 3 6
3 6 4
8 7 10
6 7 5
5 8 1
9 5 7
5 4 12
6 8 2
2
4 7
5
1 6
5 3
4 8
5 8
1 5
*/

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

plan.cpp: In function 'void dij1()':
plan.cpp:22:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   22 |         auto [new_dist, new_node] = q.top(); q.pop();
      |              ^
plan.cpp:25:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   25 |         for (auto [n, d]:node[new_node]) {
      |                   ^
plan.cpp: In function 'long long int rec(long long int, long long int)':
plan.cpp:37:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   37 |     for (auto [i,x]:node[a]) {
      |               ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...