제출 #43401

#제출 시각아이디문제언어결과실행 시간메모리
43401XmtosX007 (CEOI14_007)C++14
0 / 100
619 ms18672 KiB
#include <bits/stdc++.h>
using namespace std;
int n,m,st1,st2,a,b;
vector <int> v[300005];
int bs (int x,int y)
{
    queue<int> q;
    int lvl[300005]={0};
    lvl[x]=1;
    q.push(x);
    while (!q.empty())
    {
        int node=q.front();
        q.pop();
        if (node==y)
            return lvl[y];
        for (int i=0;i<v[node].size();i++)
        {
            if (!lvl[v[node][i]])
            {
                lvl[v[node][i]]=lvl[node]+1;
                q.push(v[node][i]);
            }
        }
    }
}
int main()
{
    cin >>n>>m>>st1>>st2>>a>>b;
    for (int i=0;i<m;i++)
    {
        int x,y;
        cin >>x>>y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    int ans1= (bs(st2,a));
    int ans2=(bs(st2,b));
    int x;
    if (ans2==ans1)
        x=max(bs(st1,a),bs(st1,b));
    else if (ans1<ans2)
        x=bs(st1,a);
    else
        x=bs(st1,b);
    ans1=min(ans1,ans2);
    if (x>ans1+1)
        cout <<-1;
    else
        cout<<ans1-x;
    return 0;
}

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

007.cpp: In function 'int bs(int, int)':
007.cpp:17:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int i=0;i<v[node].size();i++)
                       ^
007.cpp:26:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...