제출 #1327306

#제출 시각아이디문제언어결과실행 시간메모리
1327306dianaValley (BOI19_valley)C++20
36 / 100
3094 ms7744 KiB
#include <bits/stdc++.h>
#define pii pair<int, int>
#define fi first
#define se second
#define ll long long
using namespace std;
int n, s, q, e, bc;
const int N = 1e5+5;
const ll M = 1e17;
bool sh[N];
pii cel[N];
vector<pii> graf[N];

ll dfs(int v, int p)
{
    if(v == e)
        return -1;
    ll ret = M;
    for(auto x: graf[v])
        if(x.fi != p &&
           cel[bc] != make_pair(v, x.fi) &&
           cel[bc] != make_pair(x.fi, v))
        {
            ll r = dfs(x.fi, v);
            if(r == -1) ret = -1;
            ret = min(ret, r+x.se);
        }
    if(sh[v]) ret = min(ret, 0ll);
    return ret;
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    cin >> n >> s >> q >> e;
    for(int i=1; i<n; i++)
    {
        int u, v, w; cin >> u >> v >> w;
        cel[i] = {u, v};
        graf[u].push_back({v, w});
        graf[v].push_back({u, w});
    }
    for(int i=0; i<s; i++)
    {
        int c; cin >> c;
        sh[c] = 1;
    }
    while(q--)
    {
        int r; cin >> bc >> r;
        ll d = dfs(r, 0);
        if(d == -1) cout << "escaped\n";
        else if(d >= M) cout << "oo\n";
        else cout << d << '\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...