# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
382004 |
2021-03-26T09:07:20 Z |
rocks03 |
Valley (BOI19_valley) |
C++14 |
|
3000 ms |
11868 KB |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ff first
#define ss second
#define pb push_back
#define SZ(x) ((int)(x).size())
#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << ": " << x << " "
#define nl cout << "\n"
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define per(i, a, b) for(int i = (a); i >= (b); i--)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
struct Edge{
int u, w, i;
};
const int MAXN = 2e5+100;
int N, S, Q, E, shop[MAXN];
vector<Edge> g[MAXN];
void dijkstra(int s, int ind){
vector<ll> d(N, LLONG_MAX);
d[s] = 0;
priority_queue<pll, vector<pll>, greater<pll>> pq;
pq.push({d[s], s});
while(!pq.empty()){
auto [dist, v] = pq.top();
pq.pop();
if(dist > d[v]) continue;
for(auto [u, w, i] : g[v]){
if(i == ind) continue;
if(d[u] > d[v] + w){
d[u] = d[v] + w;
pq.push({d[u], u});
}
}
}
if(d[E] != LLONG_MAX){
cout << "escaped\n";
} else{
ll ans = LLONG_MAX;
rep(i, 0, S){
ans = min(ans, d[shop[i]]);
}
if(ans != LLONG_MAX){
cout << ans << "\n";
} else{
cout << "oo\n";
}
}
}
void solve(){
cin >> N >> S >> Q >> E;
--E;
rep(i, 0, N - 1){
int u, v, w;
cin >> u >> v >> w;
--u, --v;
g[u].pb({v, w, i});
g[v].pb({u, w, i});
}
rep(i, 0, S){
cin >> shop[i];
--shop[i];
}
rep(q, 0, Q){
int i, v;
cin >> i >> v;
--i, --v;
dijkstra(v, i);
}
}
int main(){
ios_base::sync_with_stdio(false), cin.tie(nullptr);
solve();
return 0;
}
Compilation message
valley.cpp: In function 'void dijkstra(int, int)':
valley.cpp:30:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
30 | auto [dist, v] = pq.top();
| ^
valley.cpp:33:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
33 | for(auto [u, w, i] : g[v]){
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
5100 KB |
Output is correct |
2 |
Correct |
25 ms |
5228 KB |
Output is correct |
3 |
Correct |
24 ms |
5228 KB |
Output is correct |
4 |
Correct |
24 ms |
5228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
5100 KB |
Output is correct |
2 |
Correct |
25 ms |
5228 KB |
Output is correct |
3 |
Correct |
24 ms |
5228 KB |
Output is correct |
4 |
Correct |
24 ms |
5228 KB |
Output is correct |
5 |
Correct |
61 ms |
5228 KB |
Output is correct |
6 |
Correct |
55 ms |
5100 KB |
Output is correct |
7 |
Correct |
53 ms |
5100 KB |
Output is correct |
8 |
Correct |
54 ms |
5100 KB |
Output is correct |
9 |
Correct |
66 ms |
5100 KB |
Output is correct |
10 |
Correct |
53 ms |
5100 KB |
Output is correct |
11 |
Correct |
54 ms |
5100 KB |
Output is correct |
12 |
Correct |
56 ms |
5228 KB |
Output is correct |
13 |
Correct |
49 ms |
5100 KB |
Output is correct |
14 |
Correct |
98 ms |
5228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3090 ms |
11868 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
5100 KB |
Output is correct |
2 |
Correct |
25 ms |
5228 KB |
Output is correct |
3 |
Correct |
24 ms |
5228 KB |
Output is correct |
4 |
Correct |
24 ms |
5228 KB |
Output is correct |
5 |
Correct |
61 ms |
5228 KB |
Output is correct |
6 |
Correct |
55 ms |
5100 KB |
Output is correct |
7 |
Correct |
53 ms |
5100 KB |
Output is correct |
8 |
Correct |
54 ms |
5100 KB |
Output is correct |
9 |
Correct |
66 ms |
5100 KB |
Output is correct |
10 |
Correct |
53 ms |
5100 KB |
Output is correct |
11 |
Correct |
54 ms |
5100 KB |
Output is correct |
12 |
Correct |
56 ms |
5228 KB |
Output is correct |
13 |
Correct |
49 ms |
5100 KB |
Output is correct |
14 |
Correct |
98 ms |
5228 KB |
Output is correct |
15 |
Execution timed out |
3090 ms |
11868 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |