# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
59189 |
2018-07-21T01:10:56 Z |
Benq |
007 (CEOI14_007) |
C++14 |
|
315 ms |
16636 KB |
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 200001;
int n,m,s,d,a,b;
vi adj[MX];
int dist[2][MX];
void genDist(int k) {
queue<int> q;
FOR(i,1,n+1) dist[k][i] = MOD;
if (k == 0) {
dist[k][a] = 0; q.push(a);
} else {
dist[k][b] = 0; q.push(b);
}
while (sz(q)) {
int x = q.front(); q.pop();
for (int i: adj[x]) if (dist[k][i] == MOD) {
dist[k][i] = dist[k][x]+1;
q.push(i);
}
}
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> m;
cin >> s >> d >> a >> b;
F0R(i,m) {
int x,y; cin >> x >> y;
adj[x].pb(y), adj[y].pb(x);
}
genDist(0), genDist(1);
cout << max(min(dist[0][d]-dist[0][s],dist[1][d]-dist[1][s])-1,-1);
}
/* Look for:
* the exact constraints (multiple sets are too slow for n=10^6 :( )
* special cases (n=1?)
* overflow (ll vs int?)
* array bounds
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
6 ms |
4984 KB |
Partially correct |
2 |
Partially correct |
7 ms |
5092 KB |
Partially correct |
3 |
Partially correct |
8 ms |
5244 KB |
Partially correct |
4 |
Correct |
9 ms |
5280 KB |
Output is correct |
5 |
Correct |
8 ms |
5280 KB |
Output is correct |
6 |
Partially correct |
6 ms |
5344 KB |
Partially correct |
7 |
Partially correct |
6 ms |
5344 KB |
Partially correct |
8 |
Correct |
7 ms |
5344 KB |
Output is correct |
9 |
Partially correct |
7 ms |
5344 KB |
Partially correct |
10 |
Partially correct |
6 ms |
5344 KB |
Partially correct |
11 |
Partially correct |
6 ms |
5344 KB |
Partially correct |
12 |
Correct |
6 ms |
5344 KB |
Output is correct |
13 |
Partially correct |
7 ms |
5372 KB |
Partially correct |
14 |
Correct |
11 ms |
5372 KB |
Output is correct |
15 |
Partially correct |
7 ms |
5372 KB |
Partially correct |
16 |
Correct |
8 ms |
5372 KB |
Output is correct |
17 |
Correct |
9 ms |
5372 KB |
Output is correct |
18 |
Correct |
8 ms |
5372 KB |
Output is correct |
19 |
Partially correct |
8 ms |
5372 KB |
Partially correct |
20 |
Partially correct |
6 ms |
5372 KB |
Partially correct |
21 |
Partially correct |
9 ms |
5372 KB |
Partially correct |
22 |
Partially correct |
8 ms |
5372 KB |
Partially correct |
23 |
Partially correct |
8 ms |
5372 KB |
Partially correct |
24 |
Correct |
8 ms |
5372 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
45 ms |
6908 KB |
Partially correct |
2 |
Correct |
59 ms |
7580 KB |
Output is correct |
3 |
Partially correct |
42 ms |
7580 KB |
Partially correct |
4 |
Correct |
41 ms |
7676 KB |
Output is correct |
5 |
Partially correct |
38 ms |
7676 KB |
Partially correct |
6 |
Partially correct |
31 ms |
7676 KB |
Partially correct |
7 |
Partially correct |
32 ms |
7676 KB |
Partially correct |
8 |
Partially correct |
41 ms |
7676 KB |
Partially correct |
9 |
Correct |
61 ms |
7692 KB |
Output is correct |
10 |
Partially correct |
179 ms |
11900 KB |
Partially correct |
11 |
Correct |
58 ms |
11900 KB |
Output is correct |
12 |
Partially correct |
85 ms |
11900 KB |
Partially correct |
13 |
Correct |
69 ms |
11900 KB |
Output is correct |
14 |
Correct |
80 ms |
11900 KB |
Output is correct |
15 |
Partially correct |
112 ms |
11900 KB |
Partially correct |
16 |
Partially correct |
76 ms |
11900 KB |
Partially correct |
17 |
Partially correct |
91 ms |
11900 KB |
Partially correct |
18 |
Correct |
71 ms |
11900 KB |
Output is correct |
19 |
Partially correct |
119 ms |
11900 KB |
Partially correct |
20 |
Correct |
220 ms |
13700 KB |
Output is correct |
21 |
Correct |
126 ms |
13700 KB |
Output is correct |
22 |
Partially correct |
134 ms |
13700 KB |
Partially correct |
23 |
Partially correct |
107 ms |
13700 KB |
Partially correct |
24 |
Partially correct |
114 ms |
13700 KB |
Partially correct |
25 |
Correct |
110 ms |
13700 KB |
Output is correct |
26 |
Partially correct |
95 ms |
13700 KB |
Partially correct |
27 |
Partially correct |
143 ms |
13700 KB |
Partially correct |
28 |
Partially correct |
166 ms |
13700 KB |
Partially correct |
29 |
Partially correct |
216 ms |
13700 KB |
Partially correct |
30 |
Correct |
315 ms |
14252 KB |
Output is correct |
31 |
Correct |
179 ms |
14252 KB |
Output is correct |
32 |
Partially correct |
156 ms |
14252 KB |
Partially correct |
33 |
Partially correct |
163 ms |
14252 KB |
Partially correct |
34 |
Correct |
148 ms |
14252 KB |
Output is correct |
35 |
Correct |
111 ms |
14252 KB |
Output is correct |
36 |
Correct |
168 ms |
14252 KB |
Output is correct |
37 |
Partially correct |
195 ms |
14252 KB |
Partially correct |
38 |
Partially correct |
199 ms |
14252 KB |
Partially correct |
39 |
Partially correct |
228 ms |
14252 KB |
Partially correct |
40 |
Correct |
247 ms |
14568 KB |
Output is correct |
41 |
Partially correct |
312 ms |
16636 KB |
Partially correct |