# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1097760 |
2024-10-08T08:16:51 Z |
icebear |
Valley (BOI19_valley) |
C++14 |
|
126 ms |
44560 KB |
// ~~ icebear ~~
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
#define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
#define FORR(i,a,b) for(int i=(a); i>=(b); --i)
#define rep(i, n) for(int i=0; i<(n); ++i)
#define red(i, n) for(int i=(n)-1; i>=0; --i)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define task "icebearat"
const int MOD = 1e9 + 7;
const int inf = 1e9 + 27092008;
const ll LLinf = 1e18 + 27092008;
const int N = 1e5 + 5;
int numNode, numQuery, numShop, esc;
ll distE[N], f[N];
vector<ii> G[N];
int h[N], tin[N], tout[N], timer = 0;
ii edge[N];
bool isShop[N];
int par[N][21], shop[N];
ll Min[N][21];
void DFS(int u) {
tin[u] = ++timer;
if (isShop[u]) {
f[u] = distE[u];
shop[u] = 1;
}
for(ii e : G[u]) {
int v, w; tie(v, w) = e;
if (v == par[u][0]) continue;
h[v] = h[u] + 1;
distE[v] = distE[u] + w;
par[v][0] = u;
DFS(v);
f[u] = min(f[u], f[v]);
shop[u] += shop[v];
}
tout[u] = timer;
}
void buildSparse() {
FOR(i, 1, numNode) Min[i][0] = f[i];
FOR(j, 1, 20) FOR(i, 1, numNode) {
par[i][j] = par[par[i][j - 1]][j - 1];
Min[i][j] = min(Min[i][j - 1], Min[par[i][j - 1]][j - 1]);
}
}
ll getQuery(int u, int acs) {
int dis = h[u] - h[acs] + 1;
ll res = LLinf;
FOR(j, 0, 20)
if ((dis >> j) & 1) {
res = min(res, Min[u][j]);
u = par[u][j];
}
return res;
}
void solve() {
cin >> numNode >> numShop >> numQuery >> esc;
FOR(i, 1, numNode - 1) {
int u, v, w;
cin >> u >> v >> w;
G[u].pb(mp(v, w));
G[v].pb(mp(u, w));
edge[i] = mp(u, v);
}
FOR(i, 1, numShop) {
int x; cin >> x;
isShop[x] = true;
}
memset(f, 0x3f, sizeof f);
DFS(esc);
FOR(i, 1, numNode) f[i] -= 2 * distE[i];
buildSparse();
while(numQuery--) {
int destroyId, node;
cin >> destroyId >> node;
int u, v; tie(u, v) = edge[destroyId];
int lower_node = (h[u] > h[v] ? u : v);
if (tin[lower_node] <= tin[node] && tout[node] <= tout[lower_node]) {
if (shop[lower_node] == 0) cout << "oo\n";
else cout << distE[node] + getQuery(node, lower_node) << '\n';
} else cout << "escaped\n";
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
if (fopen(task".inp", "r")){
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
int tc = 1;
// cin >> tc;
while(tc--) solve();
return 0;
}
Compilation message
valley.cpp: In function 'int main()':
valley.cpp:109:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
109 | freopen(task".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
valley.cpp:110:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
110 | freopen(task".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
3676 KB |
Output is correct |
2 |
Correct |
3 ms |
3644 KB |
Output is correct |
3 |
Correct |
3 ms |
3676 KB |
Output is correct |
4 |
Correct |
3 ms |
3792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
3676 KB |
Output is correct |
2 |
Correct |
3 ms |
3644 KB |
Output is correct |
3 |
Correct |
3 ms |
3676 KB |
Output is correct |
4 |
Correct |
3 ms |
3792 KB |
Output is correct |
5 |
Correct |
2 ms |
3932 KB |
Output is correct |
6 |
Correct |
2 ms |
3856 KB |
Output is correct |
7 |
Correct |
2 ms |
3932 KB |
Output is correct |
8 |
Correct |
2 ms |
3932 KB |
Output is correct |
9 |
Correct |
3 ms |
3912 KB |
Output is correct |
10 |
Correct |
3 ms |
3932 KB |
Output is correct |
11 |
Correct |
2 ms |
3928 KB |
Output is correct |
12 |
Correct |
2 ms |
3932 KB |
Output is correct |
13 |
Correct |
2 ms |
3932 KB |
Output is correct |
14 |
Correct |
2 ms |
3932 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
107 ms |
39708 KB |
Output is correct |
2 |
Correct |
126 ms |
39464 KB |
Output is correct |
3 |
Correct |
98 ms |
39248 KB |
Output is correct |
4 |
Correct |
99 ms |
41532 KB |
Output is correct |
5 |
Correct |
98 ms |
41508 KB |
Output is correct |
6 |
Correct |
111 ms |
43860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
3676 KB |
Output is correct |
2 |
Correct |
3 ms |
3644 KB |
Output is correct |
3 |
Correct |
3 ms |
3676 KB |
Output is correct |
4 |
Correct |
3 ms |
3792 KB |
Output is correct |
5 |
Correct |
2 ms |
3932 KB |
Output is correct |
6 |
Correct |
2 ms |
3856 KB |
Output is correct |
7 |
Correct |
2 ms |
3932 KB |
Output is correct |
8 |
Correct |
2 ms |
3932 KB |
Output is correct |
9 |
Correct |
3 ms |
3912 KB |
Output is correct |
10 |
Correct |
3 ms |
3932 KB |
Output is correct |
11 |
Correct |
2 ms |
3928 KB |
Output is correct |
12 |
Correct |
2 ms |
3932 KB |
Output is correct |
13 |
Correct |
2 ms |
3932 KB |
Output is correct |
14 |
Correct |
2 ms |
3932 KB |
Output is correct |
15 |
Correct |
107 ms |
39708 KB |
Output is correct |
16 |
Correct |
126 ms |
39464 KB |
Output is correct |
17 |
Correct |
98 ms |
39248 KB |
Output is correct |
18 |
Correct |
99 ms |
41532 KB |
Output is correct |
19 |
Correct |
98 ms |
41508 KB |
Output is correct |
20 |
Correct |
111 ms |
43860 KB |
Output is correct |
21 |
Correct |
77 ms |
39248 KB |
Output is correct |
22 |
Correct |
83 ms |
38776 KB |
Output is correct |
23 |
Correct |
91 ms |
38736 KB |
Output is correct |
24 |
Correct |
87 ms |
41292 KB |
Output is correct |
25 |
Correct |
109 ms |
44560 KB |
Output is correct |
26 |
Correct |
81 ms |
39284 KB |
Output is correct |
27 |
Correct |
79 ms |
38820 KB |
Output is correct |
28 |
Correct |
86 ms |
38972 KB |
Output is correct |
29 |
Correct |
91 ms |
40528 KB |
Output is correct |
30 |
Correct |
98 ms |
42244 KB |
Output is correct |
31 |
Correct |
75 ms |
39252 KB |
Output is correct |
32 |
Correct |
94 ms |
38996 KB |
Output is correct |
33 |
Correct |
85 ms |
38992 KB |
Output is correct |
34 |
Correct |
92 ms |
41040 KB |
Output is correct |
35 |
Correct |
98 ms |
44376 KB |
Output is correct |
36 |
Correct |
94 ms |
41336 KB |
Output is correct |