답안 #613954

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
613954 2022-07-30T14:30:58 Z andrei_boaca 007 (CEOI14_007) C++14
0 / 100
234 ms 17684 KB
#include <bits/stdc++.h>

using namespace std;
mt19937 rng(chrono::steady_clock().now().time_since_epoch().count());
typedef long long ll;
int n,m,s,d,a,b;
vector<int> muchii[200005];
int dist[5][200005];
void bfs(int start,int index)
{
    for(int i=1;i<=n;i++)
        dist[index][i]=1e9;
    dist[index][start]=0;
    queue<int> coada;
    coada.push(start);
    while(!coada.empty())
    {
        int nod=coada.front();
        coada.pop();
        for(int i:muchii[nod])
            if(dist[index][i]>dist[index][nod]+1)
            {
                dist[index][i]=dist[index][nod]+1;
                coada.push(i);
            }
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>m>>s>>d>>a>>b;
    for(int i=1;i<=m;i++)
    {
        int x,y;
        cin>>x>>y;
        muchii[x].push_back(y);
        muchii[y].push_back(x);
    }
    bfs(a,1);
    bfs(b,2);
    bfs(d,3);
    bfs(s,4);
    int minim=1e9;
    for(int i=1;i<=n;i++)
    {
        bool good;
        if(dist[4][i]<=1)
            good=1;
        else
        {
            good=0;
            if(dist[1][i]>=dist[1][s])
            {
                if(dist[2][i]+1>=dist[2][s])
                    good=1;
            }
            if(dist[2][i]>=dist[2][s])
            {
                if(dist[1][i]+1>=dist[1][s])
                    good=1;
            }
            if(dist[1][i]==dist[2][i]&&dist[1][s]==dist[2][s]&&dist[1][i]+1>=dist[1][s]&&dist[2][i]+1>=dist[2][s])
                good=1;
        }
        if(!good)
            minim=min(minim,dist[3][i]-2);
    }
    cout<<max(-1,minim);
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4948 KB Output is correct
2 Partially correct 3 ms 4948 KB Partially correct
3 Correct 3 ms 4948 KB Output is correct
4 Incorrect 3 ms 4948 KB Output isn't correct
5 Incorrect 3 ms 4948 KB Output isn't correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Incorrect 3 ms 4948 KB Output isn't correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Incorrect 2 ms 5076 KB Output isn't correct
13 Correct 3 ms 5076 KB Output is correct
14 Incorrect 3 ms 4948 KB Output isn't correct
15 Correct 3 ms 4948 KB Output is correct
16 Incorrect 3 ms 5076 KB Output isn't correct
17 Incorrect 3 ms 5076 KB Output isn't correct
18 Incorrect 3 ms 5076 KB Output isn't correct
19 Correct 3 ms 5076 KB Output is correct
20 Correct 3 ms 5076 KB Output is correct
21 Correct 3 ms 5076 KB Output is correct
22 Correct 3 ms 5076 KB Output is correct
23 Correct 3 ms 5092 KB Output is correct
24 Incorrect 3 ms 5076 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 6872 KB Output is correct
2 Incorrect 26 ms 7748 KB Output isn't correct
3 Correct 20 ms 6996 KB Output is correct
4 Incorrect 26 ms 7892 KB Output isn't correct
5 Correct 21 ms 6856 KB Output is correct
6 Correct 19 ms 7084 KB Output is correct
7 Correct 23 ms 7256 KB Output is correct
8 Correct 28 ms 7288 KB Output is correct
9 Incorrect 35 ms 7688 KB Output isn't correct
10 Correct 140 ms 12084 KB Output is correct
11 Incorrect 43 ms 9296 KB Output isn't correct
12 Correct 72 ms 10300 KB Output is correct
13 Incorrect 68 ms 9620 KB Output isn't correct
14 Correct 51 ms 8888 KB Output is correct
15 Correct 66 ms 10468 KB Output is correct
16 Correct 66 ms 10700 KB Output is correct
17 Correct 57 ms 10120 KB Output is correct
18 Incorrect 62 ms 10104 KB Output isn't correct
19 Correct 91 ms 11344 KB Output is correct
20 Incorrect 146 ms 14148 KB Output isn't correct
21 Incorrect 89 ms 12548 KB Output isn't correct
22 Correct 88 ms 11508 KB Output is correct
23 Partially correct 100 ms 12392 KB Partially correct
24 Correct 104 ms 12376 KB Output is correct
25 Incorrect 80 ms 12008 KB Output isn't correct
26 Partially correct 106 ms 11724 KB Partially correct
27 Correct 115 ms 12440 KB Output is correct
28 Correct 113 ms 12568 KB Output is correct
29 Correct 108 ms 12916 KB Output is correct
30 Incorrect 179 ms 14972 KB Output isn't correct
31 Incorrect 150 ms 13700 KB Output isn't correct
32 Correct 117 ms 12468 KB Output is correct
33 Partially correct 95 ms 12676 KB Partially correct
34 Incorrect 108 ms 13112 KB Output isn't correct
35 Incorrect 100 ms 12748 KB Output isn't correct
36 Incorrect 95 ms 13072 KB Output isn't correct
37 Correct 124 ms 14088 KB Output is correct
38 Correct 128 ms 13940 KB Output is correct
39 Correct 157 ms 13980 KB Output is correct
40 Incorrect 158 ms 15488 KB Output isn't correct
41 Correct 234 ms 17684 KB Output is correct