Submission #613808

# Submission time Handle Problem Language Result Execution time Memory
613808 2022-07-30T11:22:38 Z andrei_boaca 007 (CEOI14_007) C++14
0 / 100
1000 ms 20280 KB
#include <bits/stdc++.h>

using namespace std;
int n,m,s,d,a,b;
vector<int> muchii[200005];
int dist[6][200005];
bool use[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);
            }
    }
}
void dfs(int nod,int bad)
{
    use[nod]=1;
    for(int i:muchii[nod])
        if(!use[i]&&i!=bad)
            dfs(i,bad);
}
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
        {
            bfs(i,5);
            good=0;
            for(int j=1;j<=n;j++)
                if(j!=i)
                {
                    for(int k=1;k<=n;k++)
                        use[k]=0;
                    dfs(i,j);
                    if(use[a]||use[b])
                        continue;
                    if(dist[4][j]<=dist[5][j]+1)
                        good=1;
                    break;
                }
        }
        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 5 ms 4976 KB Output is correct
4 Incorrect 4 ms 4948 KB Output isn't correct
5 Incorrect 7 ms 4948 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 6 ms 5048 KB Output isn't correct
9 Correct 57 ms 4948 KB Output is correct
10 Correct 38 ms 5044 KB Output is correct
11 Correct 37 ms 5032 KB Output is correct
12 Incorrect 511 ms 5064 KB Output isn't correct
13 Execution timed out 1080 ms 5076 KB Time limit exceeded
14 Incorrect 35 ms 5040 KB Output isn't correct
15 Correct 61 ms 5044 KB Output is correct
16 Incorrect 376 ms 5076 KB Output isn't correct
17 Execution timed out 1086 ms 5076 KB Time limit exceeded
18 Execution timed out 1086 ms 5076 KB Time limit exceeded
19 Execution timed out 1090 ms 5076 KB Time limit exceeded
20 Execution timed out 1097 ms 5076 KB Time limit exceeded
21 Execution timed out 1089 ms 5076 KB Time limit exceeded
22 Execution timed out 1089 ms 5076 KB Time limit exceeded
23 Execution timed out 1088 ms 5076 KB Time limit exceeded
24 Execution timed out 1078 ms 5076 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Execution timed out 1070 ms 7372 KB Time limit exceeded
2 Execution timed out 1079 ms 8712 KB Time limit exceeded
3 Execution timed out 1087 ms 7620 KB Time limit exceeded
4 Execution timed out 1078 ms 8912 KB Time limit exceeded
5 Execution timed out 1067 ms 7424 KB Time limit exceeded
6 Execution timed out 1072 ms 8068 KB Time limit exceeded
7 Execution timed out 1081 ms 8584 KB Time limit exceeded
8 Execution timed out 1072 ms 8268 KB Time limit exceeded
9 Execution timed out 1086 ms 8756 KB Time limit exceeded
10 Execution timed out 1086 ms 13148 KB Time limit exceeded
11 Execution timed out 1080 ms 10496 KB Time limit exceeded
12 Execution timed out 1087 ms 11468 KB Time limit exceeded
13 Execution timed out 1047 ms 10740 KB Time limit exceeded
14 Execution timed out 1083 ms 9960 KB Time limit exceeded
15 Execution timed out 1080 ms 11808 KB Time limit exceeded
16 Execution timed out 1083 ms 12320 KB Time limit exceeded
17 Execution timed out 1089 ms 12748 KB Time limit exceeded
18 Execution timed out 1069 ms 11848 KB Time limit exceeded
19 Execution timed out 1083 ms 13624 KB Time limit exceeded
20 Execution timed out 1085 ms 15944 KB Time limit exceeded
21 Execution timed out 1085 ms 14704 KB Time limit exceeded
22 Execution timed out 1088 ms 13168 KB Time limit exceeded
23 Execution timed out 1080 ms 14984 KB Time limit exceeded
24 Execution timed out 1086 ms 14432 KB Time limit exceeded
25 Execution timed out 1085 ms 13760 KB Time limit exceeded
26 Execution timed out 1095 ms 13660 KB Time limit exceeded
27 Execution timed out 1091 ms 16188 KB Time limit exceeded
28 Execution timed out 1052 ms 14868 KB Time limit exceeded
29 Execution timed out 1081 ms 15088 KB Time limit exceeded
30 Execution timed out 1080 ms 16940 KB Time limit exceeded
31 Execution timed out 1079 ms 16276 KB Time limit exceeded
32 Execution timed out 1094 ms 14096 KB Time limit exceeded
33 Execution timed out 1084 ms 15044 KB Time limit exceeded
34 Execution timed out 1081 ms 14888 KB Time limit exceeded
35 Execution timed out 1054 ms 15276 KB Time limit exceeded
36 Execution timed out 1085 ms 15760 KB Time limit exceeded
37 Execution timed out 1081 ms 16884 KB Time limit exceeded
38 Execution timed out 1082 ms 18204 KB Time limit exceeded
39 Execution timed out 1073 ms 16720 KB Time limit exceeded
40 Execution timed out 1084 ms 18376 KB Time limit exceeded
41 Execution timed out 1080 ms 20280 KB Time limit exceeded