제출 #95409

#제출 시각아이디문제언어결과실행 시간메모리
95409popovicirobert007 (CEOI14_007)C++14
0 / 100
249 ms23616 KiB
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
#define ld long double
// 217
// 44

using namespace std;

const int MAXN = (int) 2e5;

vector <int> g[MAXN + 1];
int dst[MAXN + 1][2];

inline void bfs(int nod, bool t) {
    queue <int> Q;
    dst[nod][t] = 1;
    Q.push(nod);
    while(Q.size()) {
        nod = Q.front();
        Q.pop();
        for(auto it : g[nod]) {
            if(dst[it][t] == 0) {
                dst[it][t] = dst[nod][t] + 1;
                Q.push(it);
            }
        }
    }
}

int main() {
    //ifstream cin("A.in");
    //ofstream cout("A.out");
    int i, n, m, s, d, a, b;
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin >> n >> m;
    cin >> s >> d >> a >> b;
    for(i = 1; i <= m; i++) {
        int x, y;
        cin >> x >> y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    bfs(s, 0);
    bfs(d, 1);
    if(dst[a][0] > dst[a][1] || dst[b][0] > dst[b][1]) {
        cout << -1;
        return 0;
    }
    cout << min(dst[a][1] - dst[a][0], dst[b][1] - dst[b][0]);
    //cin.close();
    //cout.close();
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...