# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|
101444 | | dwsc | 007 (CEOI14_007) | C++14 | | 752 ms | 30972 KiB |
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;
int main(){
int n,m;
cin >> n >> m;
vector<int> adj[m];
int s,d,a,b;
cin >> s >> d >> a >> b;
s--;
d--;
a--;
b--;
for (int i = 0; i < m; i++){
int x,y;
cin >> x >> y;
x--;
y--;
adj[x].push_back(y);
adj[y].push_back(x);
}
queue<int> q;
int dist1[n],dist2[n];
memset(dist1,-1,sizeof(dist1));
memset(dist2,-1,sizeof(dist2));
dist1[s] = 0;
dist2[d] = 0;
q.push(s);
while (!q.empty()){
int u = q.front();
q.pop();
for (int i = 0; i < adj[u].size(); i++){
int v = adj[u][i];
if (dist1[v] == -1){
dist1[v] = dist1[u]+1;
q.push(v);
}
}
}
q.push(d);
while (!q.empty()){
int u = q.front();
q.pop();
for (int i = 0; i < adj[u].size(); i++){
int v = adj[u][i];
if (dist2[v] == -1){
dist2[v] = dist2[u]+1;
q.push(v);
}
}
}
//cout << dist1[a] << " " << dist1[b] << "\n";
//cout << dist2[a] << " " << dist2[b] << "\n";
if (dist2[a] < dist1[a] && dist2[b] < dist1[b]) cout << -1;
else cout << min(dist2[a]-dist1[a],dist2[b]-dist1[b]);
}
Compilation message (stderr)
007.cpp: In function 'int main()':
007.cpp:31:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < adj[u].size(); i++){
~~^~~~~~~~~~~~~~~
007.cpp:43:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < adj[u].size(); i++){
~~^~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |