# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
246174 | mieszko11b | 007 (CEOI14_007) | C++14 | 303 ms | 23032 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int n, m;
int s, d, a, b;
vector<int> G[200007];
int dist[200007];
bool vis[200007];
void run_bfs(int w) {
memset(vis, 0, sizeof vis);
vis[w] = 1;
dist[w] = 0;
queue<int> Q;
Q.push(w);
while(!Q.empty()) {
int u= Q.front();
Q.pop();
for(int v : G[u]) {
if(!vis[v]) {
vis[v] = 1;
dist[v] = dist[u] + 1;
Q.push(v);
}
}
}
}
int main() {
scanf("%d%d%d%d%d%d", &n, &m, &s, &d, &a, &b);
while(m--) {
int a, b;
scanf("%d%d", &a, &b);
G[a].push_back(b);
G[b].push_back(a);
}
run_bfs(s);
int sa = dist[a], sb = dist[b];
run_bfs(d);
int da = dist[a], db = dist[b];
int val = min(da - sa, db - sb);
if(val < 0) val = 0;
printf("%d\n", val - 1);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |