This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair<int, int> ii;
const int len = 2e5+5, inf = 1e9;
int dis[len], tim[len];
int n, m, s1, s2, t1, t2;
queue<int> myq;
vector<int> adj[len];
void bfs(int st){
for (int i = 1; i <= n; i++)
dis[i] = -1;
dis[st] = 0, myq.push(st);
while (!myq.empty()){
int u = myq.front();
myq.pop();
for (int j = 0; j < adj[u].size(); j++){
int v = adj[u][j];
if (dis[v] == -1)
dis[v] = dis[u]+1, myq.push(v);
}
}
}
int main(){
scanf("%d %d %d %d %d %d", &n, &m, &s1, &s2, &t1, &t2);
for (int i = 0; i < m; i++){
int a, b;
scanf("%d %d", &a, &b);
adj[a].pb(b);
adj[b].pb(a);
}
int a1, a2, b1, b2, w1, w2;
bfs(t1);
a1 = dis[s1], b1 = dis[s2], w1 = b1-a1;
bfs(t2);
a2 = dis[s1], b2 = dis[s2], w2 = b2-a2;
if (w1 > w2)
swap(a1, a2), swap(b1, b2), swap(w1, w2);
if (b1 == b2 && a1 == a2)
while (true){}
else
printf("%d\n", w1);
return 0;
}
/*
9 10
9 8 1 2
1 2
2 3
3 1
2 4
4 5
5 2
5 7
7 6
7 8
7 9
6 6
1 2 3 4
1 5
5 6
6 3
6 4
1 2
3 4
6 7
5 6 1 2
6 3
1 2
1 3
2 3
1 5
2 4
5 4
*/
Compilation message (stderr)
007.cpp: In function 'void bfs(int)':
007.cpp:26:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j = 0; j < adj[u].size(); j++){
~~^~~~~~~~~~~~~~~
007.cpp: In function 'int main()':
007.cpp:35: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, &s1, &s2, &t1, &t2);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
007.cpp:38:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &a, &b);
~~~~~^~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |