제출 #891698

#제출 시각아이디문제언어결과실행 시간메모리
891698AndreyEvacuation plan (IZhO18_plan)C++14
22 / 100
4069 ms16740 KiB
#include <bits/stdc++.h>
using namespace std;

vector<pair<int,int>> haha[100001];
vector<int> bruh(100001,INT_MAX);
vector<pair<int,int>> dsu[100001];
vector<pair<int,int>> yoo(0);

int dude(int x, int a) {
    int l = 0,r = dsu[x].size()-1;
    while(l < r) {
        int m = (l+r+1)/2;
        if(dsu[x][m].first >= a) {
            l = m;
        }
        else {
            r = m-1;
        }
    }
    yoo.push_back({x,l});
    return dsu[x][l].second;
}

int calc(int a, int t) {
    int c = a;
    yoo.clear();
    while(true) {
        int d = dude(c,t);
        if(d == c) {
            break;
        }
        c = d;
    }
    for(int i = 0; i < yoo.size(); i++) {
   //     dsu[yoo[i].first][yoo[i].second] = {dsu[yoo[i].first][yoo[i].second].first,c};
    }
    return c;
}

void upd(int a, int b, int t) {
    int c = calc(a,-1),d = calc(b,-1);
    if(c != d) {
        dsu[c].push_back({t,d});
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,m,a,b,c,k,q;
    cin >> n >> m;
    for(int i = 1; i <= n; i++) {
        dsu[i].push_back({0,i});
    }
    for(int i = 0; i < m; i++) {
        cin >> a >> b >> c;
        haha[a].push_back({b,c});
        haha[b].push_back({a,c});
    }
    cin >> k;
    priority_queue<pair<int,int>> idk;
    for(int i = 0; i < k; i++) {
        cin >> a;
        idk.push({0,a});
        bruh[a] = 0;
    }
    while(!idk.empty()) {
        a = -idk.top().first;
        b = idk.top().second;
        idk.pop();
        if(bruh[b] < a) {
            continue;
        }
        for(pair<int,int> v: haha[b]) {
            if(v.second+a < bruh[v.first]) {
                bruh[v.first] = v.second+a;
                idk.push({-v.second-a,v.first});
            }
        }
    }
    vector<pair<int,int>> wut(0);
    for(int i = 1; i <= n; i++) {
        wut.push_back({bruh[i],i});
    }
    sort(wut.begin(),wut.end());
    reverse(wut.begin(),wut.end());
    for(int i = 0; i < n; i++) {
        int s = wut[i].second;
        for(pair<int,int> v: haha[s]) {
            if(bruh[v.first] >= bruh[s]) {
                upd(s,v.first,wut[i].first);
            }
        }
    }
    cin >> q;
    for(int i = 0; i < q; i++) {
        cin >> a >> b;
        int l = 0,r = 1e9;
        while(l < r) {
            int m = (l+r+1)/2;
            if(calc(a,m) == calc(b,m)) {
                l = m;
            }
            else {
                r = m-1;
            }
        }
        cout << l << "\n";
    }
    return 0;
}

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

plan.cpp: In function 'int calc(int, int)':
plan.cpp:34:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |     for(int i = 0; i < yoo.size(); i++) {
      |                    ~~^~~~~~~~~~~~
#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...