답안 #666170

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
666170 2022-11-27T16:42:08 Z bin9638 007 (CEOI14_007) C++17
0 / 100
192 ms 19176 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]);
    val=min(val,min(dp[f[4]][2]-dp[f[3]][1]+1,dp[f[3]][2]-dp[f[4]][1]+1));
    if(val<0)
        cout<<-1;
            else cout<<val;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 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 8872 KB Output is correct
7 Correct 4 ms 8868 KB Output is correct
8 Incorrect 4 ms 8916 KB Output isn't correct
9 Correct 5 ms 8872 KB Output is correct
10 Correct 4 ms 8916 KB Output is correct
11 Correct 4 ms 8916 KB Output is correct
12 Incorrect 5 ms 8916 KB Output isn't correct
13 Correct 5 ms 8880 KB Output is correct
14 Incorrect 5 ms 8916 KB Output isn't correct
15 Correct 5 ms 8916 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 5 ms 8916 KB Output is correct
20 Correct 5 ms 8872 KB Output is correct
21 Correct 4 ms 8864 KB Output is correct
22 Correct 5 ms 8916 KB Output is correct
23 Correct 5 ms 8916 KB Output is correct
24 Incorrect 5 ms 8964 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 10404 KB Output is correct
2 Incorrect 26 ms 10916 KB Output isn't correct
3 Correct 26 ms 10528 KB Output is correct
4 Incorrect 27 ms 11084 KB Output isn't correct
5 Correct 21 ms 10320 KB Output is correct
6 Correct 20 ms 10584 KB Output is correct
7 Correct 24 ms 10708 KB Output is correct
8 Correct 26 ms 10716 KB Output is correct
9 Incorrect 40 ms 11120 KB Output isn't correct
10 Correct 107 ms 15492 KB Output is correct
11 Incorrect 39 ms 12012 KB Output isn't correct
12 Correct 60 ms 12984 KB Output is correct
13 Incorrect 44 ms 12236 KB Output isn't correct
14 Correct 36 ms 11684 KB Output is correct
15 Correct 56 ms 13036 KB Output is correct
16 Correct 56 ms 13232 KB Output is correct
17 Correct 53 ms 12672 KB Output is correct
18 Incorrect 51 ms 12620 KB Output isn't correct
19 Correct 79 ms 14024 KB Output is correct
20 Incorrect 135 ms 16872 KB Output isn't correct
21 Incorrect 80 ms 14428 KB Output isn't correct
22 Correct 77 ms 13696 KB Output is correct
23 Correct 76 ms 14280 KB Output is correct
24 Correct 80 ms 14256 KB Output is correct
25 Incorrect 85 ms 14056 KB Output isn't correct
26 Correct 73 ms 13824 KB Output is correct
27 Correct 86 ms 14424 KB Output is correct
28 Correct 83 ms 14412 KB Output is correct
29 Correct 105 ms 15244 KB Output is correct
30 Incorrect 169 ms 17220 KB Output isn't correct
31 Incorrect 90 ms 15172 KB Output isn't correct
32 Correct 82 ms 14284 KB Output is correct
33 Correct 82 ms 14588 KB Output is correct
34 Incorrect 99 ms 14808 KB Output isn't correct
35 Incorrect 73 ms 14540 KB Output isn't correct
36 Incorrect 82 ms 14760 KB Output isn't correct
37 Correct 101 ms 15496 KB Output is correct
38 Correct 95 ms 15308 KB Output is correct
39 Correct 102 ms 15388 KB Output is correct
40 Incorrect 137 ms 17016 KB Output isn't correct
41 Correct 192 ms 19176 KB Output is correct