Submission #1096288

# Submission time Handle Problem Language Result Execution time Memory
1096288 2024-10-04T08:36:01 Z snowmel Valley (BOI19_valley) C++17
36 / 100
3000 ms 13280 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int N, S, Q, H, C;
vector<pair<int,int>> QRS;
vector<tuple<int,int,ll>> edges;
vector<int> villages;
namespace sub12 {
vector<vector<int>> adj;
vector<int> is_village;
bool check() {
    return 1ll * N * Q <= int(1e6);
}
array<ll,3> dfs(int u, int p = -1) {
    array<ll,3> res;
    res[0] = res[1] = 0;
    res[2] = 1e18;
    if(u == H) res[0] = 1;
    if(is_village[u]) {
        res[1] = 1;
        res[2] = 0;
    }
    for(auto&& eid : adj[u]) {
        auto [ut, vt, w] = edges[eid];
        auto v = (ut != u ? ut : vt);
        if(v == p || w == -1) continue;
        auto t = dfs(v, u);
        res[0] |= t[0];
        res[1] |= t[1];
        if(t[1]) res[2] = min(res[2], t[2] + w);
    }
    return res;
}
void solve() {
    adj.assign(N, vector<int>());
    is_village.assign(N, 0);
    for(int i = 0; auto&& [x, y, z] : edges) {
        adj[x].emplace_back(i);
        adj[y].emplace_back(i);
        ++i;
    }
    for(auto&& v : villages) is_village[v] = 1;
    for(auto&& [x, y] : QRS) {
        auto t = get<2>(edges[x]);
        get<2>(edges[x]) = -1;
        auto tt = dfs(y);
        get<2>(edges[x]) = t;
        if(tt[0]) {
            cout << "escaped\n";
        } else if(tt[1]) {
            cout << tt[2] << "\n";
        } else {
            cout << "oo\n";
        }
    }
}
};
void solve() {
    cin >> N >> S >> Q >> H;
    --H;
    edges.resize(N - 1);
    QRS.resize(Q);
    villages.resize(S);
    for(auto& [u, v, w] : edges) {
        cin >> u >> v >> w;
        --u, --v;
    }
    for(auto& v : villages) {
        cin >> v;
        --v;
    }
    for(auto& [x, y] : QRS) {
        cin >> x >> y;
        --x, --y;
    }
    sub12::solve();
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    while(t--) solve();
}

Compilation message

valley.cpp: In function 'void sub12::solve()':
valley.cpp:37:20: warning: range-based 'for' loops with initializer only available with '-std=c++2a' or '-std=gnu++2a'
   37 |     for(int i = 0; auto&& [x, y, z] : edges) {
      |                    ^~~~
# Verdict Execution time Memory Grader output
1 Correct 9 ms 604 KB Output is correct
2 Correct 9 ms 596 KB Output is correct
3 Correct 9 ms 624 KB Output is correct
4 Correct 9 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 604 KB Output is correct
2 Correct 9 ms 596 KB Output is correct
3 Correct 9 ms 624 KB Output is correct
4 Correct 9 ms 600 KB Output is correct
5 Correct 5 ms 348 KB Output is correct
6 Correct 8 ms 348 KB Output is correct
7 Correct 14 ms 596 KB Output is correct
8 Correct 6 ms 348 KB Output is correct
9 Correct 8 ms 568 KB Output is correct
10 Correct 14 ms 600 KB Output is correct
11 Correct 6 ms 348 KB Output is correct
12 Correct 7 ms 348 KB Output is correct
13 Correct 14 ms 612 KB Output is correct
14 Correct 12 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3016 ms 13280 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 604 KB Output is correct
2 Correct 9 ms 596 KB Output is correct
3 Correct 9 ms 624 KB Output is correct
4 Correct 9 ms 600 KB Output is correct
5 Correct 5 ms 348 KB Output is correct
6 Correct 8 ms 348 KB Output is correct
7 Correct 14 ms 596 KB Output is correct
8 Correct 6 ms 348 KB Output is correct
9 Correct 8 ms 568 KB Output is correct
10 Correct 14 ms 600 KB Output is correct
11 Correct 6 ms 348 KB Output is correct
12 Correct 7 ms 348 KB Output is correct
13 Correct 14 ms 612 KB Output is correct
14 Correct 12 ms 348 KB Output is correct
15 Execution timed out 3016 ms 13280 KB Time limit exceeded
16 Halted 0 ms 0 KB -