# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
442603 | prvocislo | 007 (CEOI14_007) | C++17 | 294 ms | 18024 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;
const int maxn = 2e5 + 5;
int n, m, s, d, a, b;
vector<int> g[maxn], ds(maxn, -1), dd(maxn, -1), da(maxn, -1), db(maxn, -1);
void bfs(int st, vector<int> &d)
{
queue<int> q;
d[st] = 0; q.push(st);
while (!q.empty())
{
int u = q.front(); q.pop();
for (int v : g[u]) if (d[v] == -1) d[v] = d[u]+1, q.push(v);
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m >> s >> d >> a >> b;
s--, d--, a--, b--;
for (int i = 0, u, v; i < m; i++) cin >> u >> v, g[--u].push_back(--v), g[v].push_back(u);
bfs(s, ds), bfs(d, dd), bfs(a, da), bfs(b, db);
int wa = dd[a] - ds[a], wb = dd[b] - ds[b];
int ans;
if (wa < wb) ans = wa;
else if (wa > wb) ans = wb;
else
{
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |