Submission #110735

#TimeUsernameProblemLanguageResultExecution timeMemory
110735Mahdi_Jfri007 (CEOI14_007)C++14
0 / 100
319 ms20344 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back const int maxn = 2e5 + 20; vector<int> adj[maxn]; int d[2][maxn]; void bfs(int src , int k) { memset(d[k] , 63 , sizeof d[k]); queue<int> q; q.push(src); d[k][src] = 0; while(!q.empty()) { int v = q.front(); q.pop(); for(auto u : adj[v]) if(d[k][u] > d[k][v] + 1) { d[k][u] = d[k][v] + 1; q.push(u); } } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n , m; cin >> n >> m; int a , b , s , t; cin >> s >> t >> a >> b; s-- , t-- , a-- , b--; for(int i = 0; i < m; i++) { int a , b; cin >> a >> b; a-- , b--; adj[a].pb(b); adj[b].pb(a); } bfs(a , 0) , bfs(b , 1); if(d[0][s] > d[0][t] || d[1][s] > d[1][t]) return cout << -1 << endl , 0; cout << min(d[0][t] - d[0][s] , d[1][t] - d[1][s]) << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...