Submission #1327183

#TimeUsernameProblemLanguageResultExecution timeMemory
1327183Valters07Valley (BOI19_valley)C++20
36 / 100
3093 ms7532 KiB
#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")
#define fio ios_base::sync_with_stdio(0);cin.tie(0);
#define ll long long
#define ld long double
#define en exit(0);
#define pb push_back
#define fi first
#define se second
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N = 1e5 + 5;
const ll INF = 1e18 + 5;
vector<array<int, 3> > g[N];
bool shop[N];
int e;
ll dfs(int u, int p, int ban_id, ll curd = 0)
{
    if(u == e)
        return -1;
    ll dist = (shop[u] ? curd : INF);
    for(auto [v, w, id] : g[u])
    {
        if(id == ban_id || v == p)
            continue;
        dist = min(dist, dfs(v, u, ban_id, curd + w));
    }
    return dist;
}
int main()
{
    fio
//    ifstream cin("in.in");
    int n, s, q;
    cin >> n >> s >> q >> e;
    for(int i = 1;i < n;i++)
    {
        int u, v, w;
        cin >> u >> v >> w;
        g[u].pb({v, w, i});
        g[v].pb({u, w, i});
    }
    for(int i = 1;i <= s;i++)
    {
        int p;
        cin >> p;
        shop[p] = 1;
    }
    while(q--)
    {
        int i, r;
        cin >> i >> r;
        ll d = dfs(r, r, i);
        if(d == -1)
            cout << "escaped";
        else if(d == INF)
            cout << "oo";
        else
            cout << d;
        cout << "\n";
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...