# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
243277 | BamiTorabi | 007 (CEOI14_007) | C++14 | 371 ms | 18296 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.
//Sasayego! Sasayego! Shinzou wo Sasageyo!
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <ctime>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#include <bitset>
#include <ctime>
#define debug(x) cerr << #x << " = " << x << endl
#define lid (id << 1)
#define rid (lid ^ 1)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pll;
typedef pair <int, int> pii;
const int maxN = 2e5 + 5;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
int dist[4][maxN];
queue <int> Q;
vector <int> G[maxN];
void BFS(int ix, int st){
dist[ix][st] = 0;
Q.push(st);
while (!Q.empty()){
int v = Q.front(); Q.pop();
for (int u : G[v])
if (dist[ix][u] > dist[ix][v] + 1){
dist[ix][u] = dist[ix][v] + 1;
Q.push(u);
}
}
return;
}
int main(){
time_t START = clock();
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
memset(dist, 63, sizeof dist);
int n, m, s, t, a, b;
scanf("%d%d%d%d%d%d", &n, &m, &s, &t, &a, &b);
while (m--){
int u, v; scanf("%d%d", &u, &v);
G[u].push_back(v);
G[v].push_back(u);
}
BFS(0, s);
BFS(1, t);
BFS(2, a);
BFS(3, b);
if (dist[2][t] < dist[2][s] || dist[3][t] < dist[3][s])
return printf("-1\n"), 0;
if (dist[2][t] - dist[2][s] != dist[3][t] - dist[3][s])
return printf("%d\n", min(dist[2][t] - dist[2][s], dist[3][t] - dist[3][s])), 0;
int mns = n, mnt = n;
for (int i = 1; i <= n; i++){
if (dist[0][i] + dist[2][i] == dist[2][s] && dist[0][i] + dist[3][i] == dist[3][s])
mns = min(mns, dist[2][i]);
if (dist[1][i] + dist[2][i] == dist[2][t] && dist[1][i] + dist[3][i] == dist[3][t])
mnt = min(mnt, dist[3][i]);
}
printf("%d\n", dist[2][t] - dist[2][s] - (mnt < mns));
time_t FINISH = clock();
cerr << "Execution time: " << (ld)(FINISH - START) / CLOCKS_PER_SEC * 1000.0 << " milliseconds.\n";
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |