답안 #666167

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
666167 2022-11-27T16:39:52 Z bin9638 007 (CEOI14_007) C++17
0 / 100
209 ms 18680 KB
#include<bits/stdc++.h>

using namespace std;
#define N 200010
#define ll long long
#define ii pair<int,int>
#define fs first
#define sc second
#define pb push_back

int dp[N][5],f[5],n,m;
vector<int>g[N];
deque<int>dq;

void build(int id)
{
    dp[f[id]][id]=0;
    dq.pb(f[id]);
    while(!dq.empty())
    {
        int u=dq.front();
        dq.pop_front();
        for(auto v:g[u])
            if(dp[v][id]>dp[u][id]+1)
            {
                dp[v][id]=dp[u][id]+1;
                dq.pb(v);
            }
    }
}

int main()
{
//    freopen("A.inp","r",stdin);
//    freopen("A.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>n>>m>>f[1]>>f[2]>>f[3]>>f[4];
    for(int i=1;i<=m;i++)
    {
        int u,v;
        cin>>u>>v;
        g[u].pb(v);
        g[v].pb(u);
    }
    memset(dp,0x3f3f,sizeof(dp));
    for(int i=1;i<=2;i++)
        build(i);
    int val=min(dp[f[3]][2]-dp[f[3]][1],dp[f[4]][2]-dp[f[4]][1]);
    if(val<0)
        cout<<-1;
            else cout<<val;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8916 KB Output is correct
2 Correct 5 ms 8916 KB Output is correct
3 Correct 4 ms 8916 KB Output is correct
4 Incorrect 4 ms 8916 KB Output isn't correct
5 Incorrect 4 ms 8916 KB Output isn't correct
6 Correct 4 ms 8916 KB Output is correct
7 Correct 4 ms 8856 KB Output is correct
8 Incorrect 5 ms 8916 KB Output isn't correct
9 Correct 5 ms 8916 KB Output is correct
10 Correct 4 ms 8916 KB Output is correct
11 Correct 4 ms 8916 KB Output is correct
12 Incorrect 4 ms 8916 KB Output isn't correct
13 Correct 5 ms 8880 KB Output is correct
14 Incorrect 4 ms 8916 KB Output isn't correct
15 Correct 5 ms 8840 KB Output is correct
16 Incorrect 5 ms 8916 KB Output isn't correct
17 Incorrect 5 ms 8916 KB Output isn't correct
18 Incorrect 5 ms 8916 KB Output isn't correct
19 Correct 4 ms 8916 KB Output is correct
20 Correct 4 ms 8916 KB Output is correct
21 Correct 5 ms 8916 KB Output is correct
22 Correct 4 ms 8916 KB Output is correct
23 Correct 5 ms 8940 KB Output is correct
24 Incorrect 4 ms 8916 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 10196 KB Output is correct
2 Incorrect 30 ms 10788 KB Output isn't correct
3 Correct 20 ms 10228 KB Output is correct
4 Incorrect 26 ms 10852 KB Output isn't correct
5 Correct 18 ms 10096 KB Output is correct
6 Correct 18 ms 10272 KB Output is correct
7 Correct 22 ms 10476 KB Output is correct
8 Correct 23 ms 10400 KB Output is correct
9 Incorrect 33 ms 10872 KB Output isn't correct
10 Correct 113 ms 15096 KB Output is correct
11 Incorrect 42 ms 11736 KB Output isn't correct
12 Correct 63 ms 12440 KB Output is correct
13 Incorrect 48 ms 11920 KB Output isn't correct
14 Correct 35 ms 11496 KB Output is correct
15 Correct 53 ms 12500 KB Output is correct
16 Correct 56 ms 12684 KB Output is correct
17 Correct 49 ms 12236 KB Output is correct
18 Incorrect 55 ms 12332 KB Output isn't correct
19 Correct 77 ms 13508 KB Output is correct
20 Incorrect 144 ms 16240 KB Output isn't correct
21 Incorrect 110 ms 13900 KB Output isn't correct
22 Correct 76 ms 13264 KB Output is correct
23 Correct 71 ms 13792 KB Output is correct
24 Correct 90 ms 13856 KB Output is correct
25 Incorrect 75 ms 13568 KB Output isn't correct
26 Correct 104 ms 13436 KB Output is correct
27 Correct 95 ms 13932 KB Output is correct
28 Correct 97 ms 13900 KB Output is correct
29 Correct 97 ms 14724 KB Output is correct
30 Incorrect 147 ms 16772 KB Output isn't correct
31 Incorrect 117 ms 14696 KB Output isn't correct
32 Correct 92 ms 13772 KB Output is correct
33 Correct 99 ms 14060 KB Output is correct
34 Incorrect 100 ms 14296 KB Output isn't correct
35 Incorrect 96 ms 14092 KB Output isn't correct
36 Incorrect 102 ms 14268 KB Output isn't correct
37 Correct 113 ms 14964 KB Output is correct
38 Correct 126 ms 14856 KB Output is correct
39 Correct 137 ms 14884 KB Output is correct
40 Incorrect 165 ms 16480 KB Output isn't correct
41 Correct 209 ms 18680 KB Output is correct