| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 633181 | Alma | Valley (BOI19_valley) | C++17 | 3097 ms | 9816 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
using ll = long long;
using ii = pair<int,int>;
const int INF = 1e9;
const ll LLINF = 1e18;
using vi = vector<int>;
using vvi = vector<vi>;
void setIO (string fileName) {
ios::sync_with_stdio(false);
cin.tie(NULL);
if (fileName != "std") {
freopen((fileName + ".in").c_str(), "r", stdin);
freopen((fileName + ".out").c_str(), "w", stdout);
}
}
struct edge {
int a, b, c;
};
vector<ll> dijkstra (int n, int s, vector<vector<ii>>& adj) {
vector<ll> dist(n, LLINF);
dist[s] = 0;
priority_queue<pair<ll, int>> pq;
pq.push({0, s});
while (!pq.empty()) {
int u = pq.top().second;
ll d = -pq.top().first;
pq.pop();
if (d > dist[u]) continue;
for (ii p: adj[u]) {
int v = p.fi, c = p.se;
if (d + c < dist[v]) {
dist[v] = d+c;
pq.push({-d-c, v});
}
}
}
return dist;
}
int main() {
setIO("std");
int n, s, q, e;
cin >> n >> s >> q >> e;
e--;
vector<edge> list(n-1);
for (int i = 0; i < n-1; i++) {
cin >> list[i].a >> list[i].b >> list[i].c;
list[i].a--;
list[i].b--;
}
int x, y;
vector<bool> shop(n, false);
for (int i = 0; i < s; i++) {
cin >> x;
shop[x-1] = true;
}
while (q--) {
cin >> x >> y;
x--; y--;
vector<vector<ii>> adj(n);
for (int i = 0; i < n-1; i++) {
if (i == x) continue;
adj[list[i].a].push_back({list[i].b, list[i].c});
adj[list[i].b].push_back({list[i].a, list[i].c});
}
vector<ll> dist = dijkstra(n, y, adj);
if (dist[e] != LLINF) {
cout << "escaped\n";
} else {
ll ans = LLINF;
for (int i = 0; i < n; i++) {
if (shop[i] and dist[i] != LLINF) {
ans = min(ans, dist[i]);
}
}
if (ans == LLINF) cout << "oo\n";
else cout << ans << '\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... | ||||
