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 ll long long
#define nl '\n'
#define fu(i,a,b) for(int i=a; i<=b; i++)
#define fd(i,a,b) for(int i=a; i>=b; i--)
#define BIT(i, n) (((n)>>(i))&(1))
#define pii pair<int, int>
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define SZ(V) (int)(V.size())
#define pb push_back
#define eb emplace_back
#define NAME "quan"
int t,n,m,k,q;
const int N = 2e5 + 5;
const int MOD = 1e9 + 7;
const int inf = 1e9 + 7;
void add(int &a, int b) {a+=b; if(a>=MOD) a-=MOD;}
void sub(int &a, int b) {a-=b; if(a<0) a+=MOD;}
vector<int> adj[N];
int d[N][3];
int x,y,a,b,res;
queue<pii> Q;
void nhap(){
cin >> n >> m;
cin >> x >> y >> a >> b;
fu(i,1,m){
int u,v;
cin >> u >> v;
adj[u].eb(v);
adj[v].eb(u);
}
memset(d, -1, sizeof d);
d[a][0] = 0;
d[b][1] = 0;
d[y][2] = 0;
Q.push({a, 0});
Q.push({b, 1});
Q.push({y, 2});
while(SZ(Q)){
int u = Q.front().ff;
int x = Q.front().ss;
Q.pop();
for(int v: adj[u])
if(d[v][x] == -1){
d[v][x] = d[u][x] + 1;
Q.push({v, x});
}
}
if(d[y][0] < d[x][0] || d[y][1] < d[x][1]) cout << -1;
else{
res = inf;
fu(u,1,n)
if(d[u][0] == d[x][0] || d[u][1] == d[x][1]) res = min(res, d[u][3]);
cout << res;
}
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
if(fopen(NAME".inp", "r")){
freopen(NAME".inp", "r", stdin);
freopen(NAME".out", "w", stdout);
}
nhap();
}
Compilation message (stderr)
007.cpp: In function 'int main()':
007.cpp:70:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
70 | freopen(NAME".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
007.cpp:71:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
71 | freopen(NAME".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
007.cpp: In function 'void nhap()':
007.cpp:61:79: warning: array subscript 3 is above array bounds of 'int [3]' [-Warray-bounds]
61 | if(d[u][0] == d[x][0] || d[u][1] == d[x][1]) res = min(res, d[u][3]);
| ~~~~~~^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |