# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
668539 | RambaXGorilla | 007 (CEOI14_007) | C++17 | 220 ms | 22284 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<cstdio>
#include<algorithm>
#include<utility>
#include<vector>
#include<queue>
using namespace std;
typedef pair <int,int> ii;
int N, M, S, D, A, B;
vector <int> adj[200010];
queue <ii> near;
bool vis[200010] = {};
ii bfs(int X){
ii servers;
near.push(ii(X, 0));
while(!near.empty()){
int node = near.front().first;
int dist = near.front().second;
near.pop();
if(vis[node]) continue;
vis[node] = true;
if(node == A) servers.first = dist;
else if(node == B) servers.second = dist;
for(int i : adj[node]){
near.push(ii(i, dist + 1));
}
}
fill(vis, vis + 200010, false);
return servers;
}
int main(){
scanf("%d%d%d%d%d%d",&N,&M,&S,&D,&A,&B);
for(int i = 0;i < M;i++){
int a, b;
scanf("%d%d",&a,&b);
adj[a].push_back(b);
adj[b].push_back(a);
}
ii agent = bfs(S);
ii doctor = bfs(D);
printf("%d",max(min(doctor.first - agent.first, doctor.second - agent.second), -1));
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |