Submission #1346859

#TimeUsernameProblemLanguageResultExecution timeMemory
1346859satoulogaritEvacuation plan (IZhO18_plan)C++20
Compilation error
0 ms0 KiB
//LongvnXD
#include <bits/stdc++.h>

#define ll long long 
#define pll pair<ll, ll>
#define ii pair<int, int>
#define fi first
#define se second
#define x first
#define y second
#define all(v) v.begin(), v.end()

const int N = 2e5 + 5;
const int oo = 1e9 + 9;

using namespace std;

int n, m, k, q, d[N];
vector<ii> g[N];

namespace task5 {
    int b[N];

    bool check(int s,int t,int x) {
        for(int i = 1; i <= n; ++i) b[i] = 0;
        queue<int> q;
        q.push(s);
        b[s] = 1;
        while(q.size()) {
            int u = q.front(); q.pop();
            for(ii& temp2 : g[u]) {
                int v = temp2.fi;
                if(d[v] >= x && !b[v])
                    q.push(v), b[v] = 1;
            }
        }
        return b[t];
    }

    void solve() {
        cin >> q;
        int u, v;
        while(q--) {
            cin >> u >> v;

            int l = 0, r = min(d[u], d[v]), mid;
            while(l <= r) {
                mid = l + r >> 1;
                if(check(u, v, mid))
                    l = mid + 1;
                else
                    r = mid - 1;
            }
            cout << l - 1 << '\n';
        }
    }
}

solve() {
    task5:solve();
}

int main() {
    cin.tie(0)->sync_with_stdio(0);
    
    cin >> n >> m;
    for(int i = 1, u, v, w; i <= m; ++i) {
        cin >> u >> v >> w;
        g[u].push_back({v, w});
        g[v].push_back({u, w});
    }
    cin >> k;
    
    for(int i = 1; i <= n; ++i) d[i] = oo;
    priority_queue<ii, vector<ii>, greater<ii>> q;
    for(int i = 1, x; i <= k; ++i) {
        cin >> x;
        d[x] = 0;
        q.push({0, x});
    }
    while(q.size()) {
        ii temp = q.top(); q.pop();
        int x = temp.fi;
        int u = temp.se;

        if(d[u] != x) continue;

        for(ii& temp2 : g[u]) {
            int v = temp2.fi, w = temp2.se;
            if(d[v] > x + w) {
                d[v] = x + w;
                q.push({x + w, v});
            }
        }
    }

    solve();

    return 0;
}

Compilation message (stderr)

plan.cpp:59:1: error: ISO C++ forbids declaration of 'solve' with no type [-fpermissive]
   59 | solve() {
      | ^~~~~
plan.cpp: In function 'int solve()':
plan.cpp:61:1: warning: no return statement in function returning non-void [-Wreturn-type]
   61 | }
      | ^