Submission #613801

# Submission time Handle Problem Language Result Execution time Memory
613801 2022-07-30T11:13:24 Z andrei_boaca 007 (CEOI14_007) C++14
0 / 100
212 ms 17988 KB
#include <bits/stdc++.h>

using namespace std;
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[1][i]+1>=dist[1][s]&&dist[2][i]+1>=dist[2][s])||dist[4][i]<=1)
            good=1;
        else
            good=0;
        if(!good)
            minim=min(minim,dist[3][i]-2);
    }
    cout<<max(-1,minim);
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Incorrect 3 ms 5032 KB Output isn't correct
5 Incorrect 3 ms 5052 KB Output isn't correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Incorrect 2 ms 4948 KB Output isn't correct
9 Correct 3 ms 5032 KB Output is correct
10 Correct 4 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Incorrect 3 ms 5076 KB Output isn't correct
13 Correct 3 ms 5076 KB Output is correct
14 Incorrect 2 ms 4948 KB Output isn't correct
15 Correct 3 ms 5032 KB Output is correct
16 Incorrect 3 ms 5036 KB Output isn't correct
17 Incorrect 3 ms 5040 KB Output isn't correct
18 Incorrect 3 ms 5076 KB Output isn't correct
19 Correct 4 ms 5032 KB Output is correct
20 Correct 3 ms 5032 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 5076 KB Output is correct
24 Incorrect 3 ms 5076 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 7276 KB Output is correct
2 Incorrect 29 ms 8132 KB Output isn't correct
3 Correct 22 ms 7320 KB Output is correct
4 Incorrect 27 ms 8312 KB Output isn't correct
5 Correct 24 ms 7164 KB Output is correct
6 Correct 21 ms 7432 KB Output is correct
7 Correct 29 ms 7636 KB Output is correct
8 Correct 25 ms 7652 KB Output is correct
9 Incorrect 34 ms 8112 KB Output isn't correct
10 Correct 117 ms 12456 KB Output is correct
11 Incorrect 52 ms 9652 KB Output isn't correct
12 Correct 78 ms 10628 KB Output is correct
13 Incorrect 55 ms 10056 KB Output isn't correct
14 Correct 40 ms 9204 KB Output is correct
15 Correct 64 ms 10848 KB Output is correct
16 Correct 70 ms 11144 KB Output is correct
17 Correct 58 ms 10444 KB Output is correct
18 Incorrect 61 ms 10536 KB Output isn't correct
19 Correct 89 ms 11736 KB Output is correct
20 Incorrect 163 ms 14472 KB Output isn't correct
21 Incorrect 90 ms 12876 KB Output isn't correct
22 Correct 105 ms 11936 KB Output is correct
23 Correct 95 ms 12820 KB Output is correct
24 Correct 86 ms 12716 KB Output is correct
25 Incorrect 84 ms 12496 KB Output isn't correct
26 Correct 91 ms 12032 KB Output is correct
27 Correct 95 ms 12848 KB Output is correct
28 Correct 104 ms 12844 KB Output is correct
29 Correct 123 ms 13440 KB Output is correct
30 Incorrect 172 ms 15532 KB Output isn't correct
31 Incorrect 105 ms 14016 KB Output isn't correct
32 Correct 100 ms 12760 KB Output is correct
33 Correct 113 ms 13112 KB Output is correct
34 Incorrect 131 ms 13520 KB Output isn't correct
35 Incorrect 95 ms 13132 KB Output isn't correct
36 Incorrect 112 ms 13400 KB Output isn't correct
37 Correct 130 ms 14560 KB Output is correct
38 Correct 121 ms 14352 KB Output is correct
39 Correct 135 ms 14260 KB Output is correct
40 Incorrect 163 ms 15892 KB Output isn't correct
41 Correct 212 ms 17988 KB Output is correct