# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
568188 | mat_v | Valley (BOI19_valley) | C++14 | 226 ms | 44360 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
#define fb(i,a,b) for(int (i) = (a); (i) >= (b); --(i))
#define mod 998244353
#define xx first
#define yy second
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define ll long long
#define pii pair<int,ll>
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;/// find_by_order(x)(x+1th) , order_of_key() (strictly less)
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
int n,m,q,e;
struct gr{
int a;
int b;
ll w;
};
gr edges[100005];
vector<pii> graf[100005];
int lca[100005][20];
ll najm[100005][20];
int disc[100005];
int out[100005];
ll dub[100005];
ll dp[100005];
bool dobar[100005];
int br;
ll pom = 1e8;
void dfs(int x, int y, ll z){
lca[x][0] = y;
disc[x] = br;
dub[x] = z;
dp[x] = pom;
if(dobar[x])dp[x] = 0;
for(auto c:graf[x]){
if(c.xx == y)continue;
br++;
dfs(c.xx,x,z+c.yy);
dp[x] = min(dp[x], dp[c.xx] + c.yy);
}
out[x] = br;
najm[x][0] = (dp[x] - dub[x]);
}
void resilca(int x, int y){
ff(j,1,19){
lca[x][j] = lca[lca[x][j-1]][j-1];
najm[x][j] = min(najm[x][j - 1], najm[lca[x][j-1]][j-1]);
}
for(auto c:graf[x]){
if(c.xx == y)continue;
resilca(c.xx, x);
}
}
bool insubtr(int x, int y){
if(x == 0)return 1;
if(x == y)return 1;
if(disc[y] >= disc[x] && disc[y] <= out[x])return 1;
return 0;
}
int main()
{
ios_base::sync_with_stdio(false); cin.tie(0);
pom *= pom;
cin >> n >> m >> q >> e;
ff(i,1,n)dp[i] = pom;
ff(i,1,n - 1){
int x,y,z;
cin >> x >> y >> z;
edges[i] = {x,y,z};
graf[x].pb({y,z});
graf[y].pb({x,z});
}
ff(i,1,m){
int x;
cin >> x;
dobar[x] = 1;
}
ff(i,1,n)dp[i] += dub[i];
br = 1;
dfs(e,0,1);
resilca(e,0);
ll mks = 1e9;
ll mks2 = 1e5;
mks *= mks2;
while(q--){
int r,y;
cin >> r >> y;
int koji = edges[r].a;
if(dub[edges[r].a] < dub[edges[r].b])koji = edges[r].b;
if(!insubtr(koji,y)){
cout << "escaped\n";
continue;
}
ll ans = pom;
ll dlt = dub[y];
fb(j,19,0){
if(insubtr(koji,lca[y][j])){
ans = min(ans, najm[y][j]);
y = lca[y][j];
}
}
ans = min(ans, najm[y][0]);
if(ans > mks)cout << "oo\n";
else cout << ans + dlt << "\n";
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |