# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
82418 | Flying_dragon_02 | 007 (CEOI14_007) | C++14 | 363 ms | 16568 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
typedef pair<int, int> ii;
const int N = 2e5 + 5;
int n, m, s, d, a, b, dist[2][N];
const int inf = 1e8;
vector<int> graph[N];
queue<ii> pq;
int main() {
//freopen("spy.inp", "r", stdin);
//freopen("spy.out", "w", stdout);
scanf("%d%d", &n, &m);
scanf("%d%d%d%d", &s, &d, &a, &b);
for(int i = 1; i <= n; i++)
dist[0][i] = dist[1][i] = inf;
for(int i = 0; i < m; i++) {
int u, v;
scanf("%d%d", &u, &v);
graph[u].pb(v);
graph[v].pb(u);
}
dist[0][s] = 0;
pq.push({dist[0][s], s});
while(!pq.empty()) {
ii frt = pq.front();
pq.pop();
int u = frt.se;
if(frt.fi > dist[0][u]) continue;
for(int i = 0; i < graph[u].size(); i++) {
int v = graph[u][i];
if(dist[0][u] + 1 < dist[0][v]) {
dist[0][v] = dist[0][u] + 1;
pq.push({dist[0][v], v});
}
}
}
dist[1][d] = 0;
pq.push({dist[1][d], d});
while(!pq.empty()) {
ii frt = pq.front();
pq.pop();
int u = frt.se;
if(frt.fi > dist[1][u]) continue;
for(int i = 0; i < graph[u].size(); i++) {
int v = graph[u][i];
if(dist[1][u] + 1 < dist[1][v]) {
dist[1][v] = dist[1][u] + 1;
pq.push({dist[1][v], v});
}
}
}
if(dist[1][a] >= dist[0][a] && dist[1][b] >= dist[0][b])
printf("%d", min(dist[1][a] - dist[0][a], dist[1][b] - dist[0][b]));
else
printf("-1");
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |