Submission #110767

# Submission time Handle Problem Language Result Execution time Memory
110767 2019-05-12T08:01:18 Z MAMBA 007 (CEOI14_007) C++17
30 / 100
358 ms 38520 KB
#include <bits/stdc++.h> 

using namespace std;

#define rep(i , j , k) for (int i = j; i < (int)k; i++)
#define pb push_back
#define mt make_tuple
#define for_all(x) x.begin(),x.end()

typedef long long ll;
typedef pair<int , int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef long double ld;
typedef complex<ld> point;

inline void fileIO(string s) {
	freopen((s + ".in").c_str(), "r", stdin);
	freopen((s + ".out").c_str(), "w", stdout);
}

template<class T , class S>
inline bool smin(T &a, S b) { return (T)b < a ? a = b , 1 : 0; }
template<class T , class S>
inline bool smax(T &a, S b) { return a < (T)b ? a = b , 1 : 0; }

constexpr int N = 1e6 + 10;

constexpr int MOD = 1e9 + 7;

template<typename T>
inline T mod(T &v) { return v = (v % MOD + MOD) % MOD; }
template<typename S, typename T>
inline S add(S &l, T r) { return mod(l += r); }

ll po(ll v, ll u) { return u ? po(v * v % MOD , u >> 1) * (u & 1 ? v : 1) % MOD : 1; }

int n , m;
int s , t , a , b, dist[N];
vector<int> adj[N];
int L , R , Q[N];

void bfs(int so) {
	memset(dist , -1, sizeof(dist));
	dist[so] = 0;
	L = 0, R = 1;
	Q[0] = so;
	while (L < R) {
		int me = Q[L++];
		for (auto e : adj[me])
			if (!~dist[e]) {
				dist[e] = dist[me] + 1;
				Q[R++] = e;
			}
	}
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);

#ifndef LOCAL
	//	fileIO("forbidden1");
#endif

	cin >> n >> m >> s >> t >> a >> b;
	rep(i , 0 , m) {
		int u , v;
		cin >> u >> v;
		adj[u].pb(v);
		adj[v].pb(u);
	}

	bfs(s);
	int A = dist[a];
	int B = dist[b];
	bfs(t);
	int C = dist[a];
	int D = dist[b];

	int res = min(C - A , D - B);

  res--;
	if (res < 0) res = -1;
	cout << res << endl;


	return 0;
}
# Verdict Execution time Memory Grader output
1 Partially correct 26 ms 27776 KB Partially correct
2 Partially correct 27 ms 27724 KB Partially correct
3 Partially correct 26 ms 27776 KB Partially correct
4 Correct 27 ms 27776 KB Output is correct
5 Correct 32 ms 27776 KB Output is correct
6 Partially correct 27 ms 27776 KB Partially correct
7 Partially correct 26 ms 27776 KB Partially correct
8 Correct 26 ms 27748 KB Output is correct
9 Partially correct 27 ms 27768 KB Partially correct
10 Partially correct 26 ms 27776 KB Partially correct
11 Partially correct 25 ms 27776 KB Partially correct
12 Correct 29 ms 27688 KB Output is correct
13 Partially correct 30 ms 27768 KB Partially correct
14 Correct 31 ms 27768 KB Output is correct
15 Partially correct 27 ms 27776 KB Partially correct
16 Correct 28 ms 27776 KB Output is correct
17 Correct 32 ms 27740 KB Output is correct
18 Correct 28 ms 27772 KB Output is correct
19 Partially correct 33 ms 27896 KB Partially correct
20 Partially correct 32 ms 27768 KB Partially correct
21 Partially correct 30 ms 27772 KB Partially correct
22 Partially correct 30 ms 27776 KB Partially correct
23 Partially correct 29 ms 27768 KB Partially correct
24 Correct 28 ms 27776 KB Output is correct
# Verdict Execution time Memory Grader output
1 Partially correct 47 ms 29192 KB Partially correct
2 Correct 62 ms 29816 KB Output is correct
3 Partially correct 52 ms 29304 KB Partially correct
4 Correct 62 ms 29944 KB Output is correct
5 Partially correct 49 ms 29048 KB Partially correct
6 Partially correct 51 ms 29304 KB Partially correct
7 Partially correct 57 ms 29432 KB Partially correct
8 Partially correct 57 ms 29432 KB Partially correct
9 Correct 66 ms 29816 KB Output is correct
10 Partially correct 168 ms 34140 KB Partially correct
11 Correct 79 ms 30968 KB Output is correct
12 Partially correct 109 ms 31736 KB Partially correct
13 Correct 80 ms 31224 KB Output is correct
14 Correct 103 ms 30584 KB Output is correct
15 Partially correct 122 ms 31872 KB Partially correct
16 Partially correct 133 ms 32168 KB Partially correct
17 Partially correct 84 ms 31564 KB Partially correct
18 Correct 82 ms 31608 KB Output is correct
19 Partially correct 128 ms 32760 KB Partially correct
20 Correct 260 ms 35676 KB Output is correct
21 Correct 128 ms 33452 KB Output is correct
22 Partially correct 112 ms 32632 KB Partially correct
23 Partially correct 170 ms 33400 KB Partially correct
24 Partially correct 126 ms 33272 KB Partially correct
25 Correct 142 ms 33088 KB Output is correct
26 Partially correct 115 ms 32712 KB Partially correct
27 Partially correct 126 ms 33372 KB Partially correct
28 Partially correct 150 ms 33360 KB Partially correct
29 Partially correct 191 ms 34156 KB Partially correct
30 Correct 268 ms 36216 KB Output is correct
31 Correct 147 ms 34168 KB Output is correct
32 Partially correct 191 ms 33272 KB Partially correct
33 Partially correct 144 ms 33528 KB Partially correct
34 Correct 194 ms 33976 KB Output is correct
35 Correct 122 ms 33628 KB Output is correct
36 Correct 128 ms 33824 KB Output is correct
37 Partially correct 174 ms 34676 KB Partially correct
38 Partially correct 168 ms 34424 KB Partially correct
39 Partially correct 188 ms 34404 KB Partially correct
40 Correct 242 ms 36112 KB Output is correct
41 Partially correct 358 ms 38520 KB Partially correct