Submission #1327186

#TimeUsernameProblemLanguageResultExecution timeMemory
1327186Valters07Valley (BOI19_valley)C++20
0 / 100
3091 ms2044 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<pair<int,int> > edg;
int w[N];
bool shop[N];
int main()
{
    fio
//    ifstream cin("in.in");
    int n, s, q, e;
    cin >> n >> s >> q >> e;
    edg.resize(n - 1);
    for(int i = 0;i < n - 1;i++)
    {
        int u, v;
        cin >> u >> v;
        if(u > v)
            swap(u, v);
        cin >> w[u];
        edg[i] = {u, v};
    }
    for(int i = 1;i <= s;i++)
    {
        int p;
        cin >> p;
        shop[p] = 1;
    }
    while(q--)
    {
        int i, r;
        cin >> i >> r;
        int u = edg[i - 1].fi, v = edg[i - 1].se;
        if(u > v)
            swap(u, v);
        ll best = INF, cur = 0;
        if(r == e)
            best = -1;
        if(shop[r])
            best = 0;
        if(r != u)
        {
            for(int i = r + 1;i <= n;i++)
            {
                cur += w[i - 1];
                if(shop[i])
                    best = min(best, cur);
                if(i == e)
                    best = -1;
                if(i == u)
                    break;
            }
        }
        if(r != v)
        {
            cur = 0;
            for(int i = r - 1;i >= 1;i--)
            {
                cur += w[i];
                if(shop[i])
                    best = min(best, cur);
                if(i == e)
                    best = -1;
                if(i == v)
                    break;
            }
        }
        if(best == -1)
            cout << "escaped";
        else if(best == INF)
            cout << "oo";
        else
            cout << best;
        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...