# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
132330 | bogdan10bos | 007 (CEOI14_007) | C++14 | 365 ms | 17784 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/// 00:04 why?
#include <bits/stdc++.h>
using namespace std;
const int NMAX = 2e5 + 5;
int N, M, S, D, A, B;
vector<int> edg[NMAX];
vector<int> BFS(int start)
{
vector<int> d(N + 1, 1 << 30);
d[start] = 0;
queue<int> q;
q.push(start);
while(!q.empty())
{
int nod = q.front();
q.pop();
for(auto nxt: edg[nod])
if(d[nxt] > d[nod] + 1)
{
d[nxt] = d[nod] + 1;
q.push(nxt);
}
}
return d;
}
int main()
{
//freopen("1.in", "r", stdin);
scanf("%d%d", &N, &M);
scanf("%d%d%d%d", &S, &D, &A, &B);
for(int i = 1; i <= M; i++)
{
int x, y;
scanf("%d%d", &x, &y);
edg[x].push_back(y);
edg[y].push_back(x);
}
auto dS = BFS(S);
auto dD = BFS(D);
if(dD[A] + 1 <= dS[A] || dD[B] + 1 <= dS[B])
{
printf("-1\n");
exit(0);
}
int timp = -1;
if(dD[A] - dS[A] != dD[B] - dS[B])
timp = min(dD[A] - dS[A], dD[B] - dS[B]);
else
{
auto dA = BFS(A);
auto dB = BFS(B);
int maxStepsS = 0;
for(int i = 1; i <= N; i++)
if(dA[i] == dB[i] && dA[i] + dS[i] == dS[A])
maxStepsS = max(maxStepsS, dS[i]);
int maxStepsD = 0;
for(int i = 1; i <= N; i++)
if(dA[i] == dB[i] && dA[i] + dD[i] == dD[A])
maxStepsD = max(maxStepsD, dD[i]);
timp = min(dD[A] - dS[A], dD[B] - dS[B]);
maxStepsD -= (dD[A] - dS[A]);
if(maxStepsS < maxStepsD) timp--;
}
printf("%d\n", timp);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |