이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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][2];
int x,y,a,b;
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;
Q.push({a, 0});
Q.push({b, 1});
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 cout << min(d[y][0] - d[x][0], d[y][1] - d[x][1]);
}
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();
}
컴파일 시 표준 에러 (stderr) 메시지
007.cpp: In function 'int main()':
007.cpp:63:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
63 | freopen(NAME".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
007.cpp:64:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
64 | freopen(NAME".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |