제출 #526452

#제출 시각아이디문제언어결과실행 시간메모리
526452azert9526Evacuation plan (IZhO18_plan)C++14
22 / 100
4058 ms11092 KiB
#include <bits/stdc++.h>

#define ll long long
#define MOD 1000000007

using namespace std;

int n, m, k;
vector< pair<int, int> > g[100005];
bool isnpp[100005] = {0};
int cln[100005] = {0};
bool used[100005] = {0};

void getclosestnpp(int x)
{
    if(isnpp[x]) return;

    for(int i = 1; i <= n; i++) used[i] = 0;
    priority_queue< pair<int, int> > pq;
    pq.push({0, x});
    while(!pq.empty())
    {
        int c = -pq.top().first, v = pq.top().second;
        pq.pop();
        if(isnpp[v])
        {
            cln[x] = c;
            return;
        }
        if(!used[v])
        {
            used[v] = true;
            for(pair<int, int> u : g[v])
            {
                if(!used[u.first]) pq.push({-c-u.second, u.first});
            }
        }
    }
}

int solve(int s, int t)
{
    if(isnpp[s] || isnpp[t]) return 0;

    for(int i = 1; i <= n; i++) used[i] = 0;
    priority_queue< pair<int, int> > pq;
    pq.push({cln[s], s});
    while(!pq.empty())
    {
        int d = pq.top().first, v = pq.top().second;
        pq.pop();
        if(v == t)
        {
            return d;
        }
        if(!used[v])
        {
            used[v] = true;
            for(pair<int, int> u : g[v])
            {
                if(!used[u.first]) pq.push({min(d, cln[u.first]), u.first});
            }
        }
    }
}

int main()
{
    //ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    cin>>n>>m;
    for(int i = 0; i < m; i++)
    {
        int x, y, w;
        cin>>x>>y>>w;
        g[x].push_back({y, w});
        g[y].push_back({x, w});
    }

    cin>>k;
    for(int i = 0; i < k; i++)
    {
        int x;
        cin>>x;
        isnpp[x] = true;
    }

    for(int i = 1; i <= n; i++) getclosestnpp(i);

    int q;
    cin>>q;
    for(int i = 0; i < q; i++)
    {
        int s, t;
        cin>>s>>t;
        cout<<solve(s, t)<<'\n';
    }

    return 0;
}

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

plan.cpp: In function 'int solve(int, int)':
plan.cpp:46:38: warning: control reaches end of non-void function [-Wreturn-type]
   46 |     priority_queue< pair<int, int> > pq;
      |                                      ^~
#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...