제출 #101517

#제출 시각아이디문제언어결과실행 시간메모리
101517cheeheng007 (CEOI14_007)C++14
0 / 100
345 ms15612 KiB
#include <bits/stdc++.h>

using namespace std;

vector<int> AdjList[200005];
int dist[200005];

int main(){
    int N, M;
    int s, d, a, b;
    scanf("%d%d%d%d%d%d", &N, &M, &s, &d, &a, &b);

    for(int i = 0; i < M; i ++){
        int x, y;
        scanf("%d%d", &x, &y);
        AdjList[x].push_back(y);
        AdjList[y].push_back(x);
    }

    memset(dist, -1, sizeof(dist));
    queue<int> q;
    q.push(s);
    dist[s] = 0;
    while(!q.empty()){
        int u = q.front(); q.pop();
        for(int v: AdjList[u]){
            if(dist[v] == -1){
                dist[v] = dist[u] + 1;
                q.push(v);
            }
        }
    }

    int sa = dist[a];
    int sb = dist[b];

    memset(dist, -1, sizeof(dist));
    q = queue<int>();
    q.push(d);
    dist[d] = 0;
    while(!q.empty()){
        int u = q.front(); q.pop();
        for(int v: AdjList[u]){
            if(dist[v] == -1){
                dist[v] = dist[u] + 1;
                q.push(v);
            }
        }
    }

    int da = dist[a];
    int db = dist[b];

    //printf("%d %d %d %d\n", sa, sb, da, db);

    int resA = min(da-sa, db-sa-1);
    int resB = min(da-sb-1, da-sb);
    int res = max(resA, resB);
    int ans = max(res, -1);
    if(db-sa-1 == da-sb-1){
        ans ++;
    }
    printf("%d", ans);
}

컴파일 시 표준 에러 (stderr) 메시지

007.cpp: In function 'int main()':
007.cpp:11:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d%d%d%d%d", &N, &M, &s, &d, &a, &b);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
007.cpp:15:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &x, &y);
         ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...