제출 #565929

#제출 시각아이디문제언어결과실행 시간메모리
565929RealSnakeEvacuation plan (IZhO18_plan)C++14
19 / 100
447 ms27164 KiB
#include "bits/stdc++.h"
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

#define ll long long
#define mod 1000000007

ofstream fout(".out");
ifstream fin(".in");

vector<pair<int, int>> v[100001], qq[100001];
int d[100001], g[100001], ans[100001];
bool vis[100001];
vector<int> o[100001];
int n, m, s, t;

void combine(int x, int y, int dis) {
    if(g[x] == g[y])
        return;
    if(o[x].size() < o[y].size())
        swap(x, y);
    for(int i : o[y]) {
        for(auto [k, j] : qq[i]) {
            if(g[k] == x)
                ans[j] = dis;
        }
        g[i] = x;
        o[x].push_back(i);
    }
}

signed main() {

    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    cin >> n >> m;
    for(int i = 1; i <= n; i++)
        d[i] = 1e9;
    for(int i = 0; i < m; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        v[a].push_back({b, c});
        v[b].push_back({a, c});
    }
    int k;
    cin >> k;
    set<pair<int, int>> ss;
    for(int i = 0; i < k; i++) {
        int x;
        cin >> x;
        d[x] = 0;
        ss.insert({0, x});
    }
    while(ss.size()) {
        pair<int, int> p = *ss.begin();
        ss.erase(ss.begin());
        int x = p.second;
        int cost = p.first;
        if(cost > d[x])
            continue;
        d[x] = cost;
        for(auto i : v[x]) {
            if(cost + i.second < d[i.first]) {
                d[i.first] = cost + i.second;
                ss.insert({cost + i.second, i.first});
            }
        }
    }
    int q;
    cin >> q;
    for(int i = 0; i < q; i++) {
        cin >> s >> t;
        qq[s].push_back({t, i});
        qq[t].push_back({s, i});
    }
    vector<pair<int, int>> ve;
    for(int i = 1; i <= n; i++) {
        ve.push_back({d[i], i});
        g[i] = i;
        o[i].push_back(i);
    }
    sort(ve.rbegin(), ve.rend());
    for(auto [dis, x] : ve) {
        for(auto [i, cost] : v[x]) {
            if(vis[i])
                combine(g[x], g[i], dis);
        }
        vis[x] = 1;
    }
    for(int i = 0; i < q; i++)
        cout << ans[i] << "\n";

    return 0;
}

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

plan.cpp: In function 'void combine(int, int, int)':
plan.cpp:27:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   27 |         for(auto [k, j] : qq[i]) {
      |                  ^
plan.cpp: In function 'int main()':
plan.cpp:89:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   89 |     for(auto [dis, x] : ve) {
      |              ^
plan.cpp:90:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   90 |         for(auto [i, cost] : v[x]) {
      |                  ^
#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...