Submission #565745

#TimeUsernameProblemLanguageResultExecution timeMemory
565745AbdullahMWEvacuation plan (IZhO18_plan)C++14
0 / 100
1423 ms524288 KiB
#include <bits/stdc++.h>

#define all(vec) vec.begin(), vec.end()
#define ll long long
#define db double
#define pb push_back
#define pf push_front
#define newl "\n"
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define f first
#define s second
#define MOD 1000000007

using namespace std;

vector <pair <ll, ll>> gr[100005];
unordered_map <ll, bool> nuc;

ll dj(ll beg)
{
    priority_queue <pair <ll, ll>, vector <pair <ll, ll>>, greater <pair <ll, ll>>> pq;
    unordered_map <ll, ll> vis;
    pq.push({0, beg});
    
    
    while (pq.size())
    {
        ll c = pq.top().s, len = pq.top().f;
        pq.pop();
        if (!vis[c])
        {
            if (nuc[c]) return len;
            for (auto v : gr[c])
            {
                pq.push({len + v.f, v.s});
            }
        }
    }
}

int main()
{
    fast
    //setIO("");
    
    //freopen("filename.in", "r", stdin);
    //freopen("filename.out", "w", stdout);
    
    
    ll n, m; cin >> n >> m;
    for (ll i = 1; i <= m; i++)
    {
        ll x, y, len;
        
        cin >> x >> y >> len;
        gr[x].pb({len, y});
        gr[y].pb({len, x});
    }
    
    ll k; cin >> k;
    for (ll i = 1; i <= k; i++)
    {
        ll idx; cin >> idx;
        nuc[idx] = true;
    }
    
    
    //cout << newl;
    ll q; cin >> q;
    while (q--)
    {
        ll x, y; cin >> x >> y;
        cout << min(dj(x), dj(y));
    }
    
    /*cout << newl;
    for (ll i = 1; i <= n; i++)
    {
        if (!nuc[i]) cout << "City: " << i << " Dist: " << fin[i] << newl;
    }*/
    
    
}
    

Compilation message (stderr)

plan.cpp: In function 'long long int dj(long long int)':
plan.cpp:21:85: warning: control reaches end of non-void function [-Wreturn-type]
   21 |     priority_queue <pair <ll, ll>, vector <pair <ll, ll>>, greater <pair <ll, ll>>> 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...