# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
218308 |
2020-04-02T00:15:03 Z |
alishahali1382 |
007 (CEOI14_007) |
C++14 |
|
300 ms |
18040 KB |
#include <bits/stdc++.h>
#pragma GCC optimize ("O2")
#pragma GCC optimize ("unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) {cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;}
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;
const ld eps=1e-7;
const int inf=1000000010;
const ll INF=10000000000000010LL;
const int mod = 1000000007;
const int MAXN = 200010, LOG=20;
int n, m, k, u, v, x, y, t, a, b, ans;
int dist[4][MAXN];
vector<int> G[MAXN];
queue<int> Q;
void BFS(int* dist, int src){
dist[src]=0;
Q.push(src);
while (Q.size()){
int v=Q.front();
Q.pop();
for (int u:G[v]) if (dist[v]+1<dist[u]){
dist[u]=dist[v]+1;
Q.push(u);
}
}
}
int main(){
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
memset(dist, 31, sizeof(dist));
cin>>n>>m>>k>>t>>a>>b;
while (m--){
cin>>u>>v;
G[u].pb(v);
G[v].pb(u);
}
BFS(dist[0], a);
BFS(dist[1], b);
BFS(dist[2], k);
BFS(dist[3], t);
int fk=inf, ft=inf;
if (dist[0][k]==dist[1][k]){
for (int v=1; v<=n; v++){
if (dist[0][v]==dist[1][v] && dist[0][v]+dist[2][v]==dist[0][k]) fk=min(fk, dist[0][v]);
}
}
if (dist[0][t]==dist[1][t]){
for (int v=1; v<=n; v++){
if (dist[0][v]==dist[1][v] && dist[0][v]+dist[3][v]==dist[0][t]) ft=min(ft, dist[0][v]);
}
}
int dt=min(dist[0][t], dist[1][t]), dk=min(dist[0][k], dist[1][k]);
ans=dt-dk;
if (fk==inf && ft==inf){
int optk=(dist[1][k]==dk);
int optt=(dist[1][t]==dt);
ans-=(optk!=optt);
}
else ans-=(fk>ft);
if (ans<0) ans=-1;
cout<<ans<<'\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
8192 KB |
Output is correct |
2 |
Correct |
9 ms |
8192 KB |
Output is correct |
3 |
Correct |
9 ms |
8192 KB |
Output is correct |
4 |
Correct |
9 ms |
8192 KB |
Output is correct |
5 |
Correct |
9 ms |
8192 KB |
Output is correct |
6 |
Correct |
9 ms |
8192 KB |
Output is correct |
7 |
Correct |
9 ms |
8192 KB |
Output is correct |
8 |
Correct |
9 ms |
8192 KB |
Output is correct |
9 |
Correct |
9 ms |
8192 KB |
Output is correct |
10 |
Correct |
9 ms |
8192 KB |
Output is correct |
11 |
Correct |
9 ms |
8192 KB |
Output is correct |
12 |
Correct |
9 ms |
8192 KB |
Output is correct |
13 |
Correct |
9 ms |
8192 KB |
Output is correct |
14 |
Correct |
9 ms |
8192 KB |
Output is correct |
15 |
Correct |
9 ms |
8192 KB |
Output is correct |
16 |
Correct |
9 ms |
8192 KB |
Output is correct |
17 |
Correct |
9 ms |
8192 KB |
Output is correct |
18 |
Correct |
10 ms |
8192 KB |
Output is correct |
19 |
Correct |
9 ms |
8192 KB |
Output is correct |
20 |
Correct |
9 ms |
8192 KB |
Output is correct |
21 |
Correct |
9 ms |
8192 KB |
Output is correct |
22 |
Correct |
9 ms |
8192 KB |
Output is correct |
23 |
Correct |
9 ms |
8192 KB |
Output is correct |
24 |
Correct |
9 ms |
8192 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
9728 KB |
Output is correct |
2 |
Correct |
40 ms |
10232 KB |
Output is correct |
3 |
Correct |
33 ms |
9728 KB |
Output is correct |
4 |
Correct |
40 ms |
10368 KB |
Output is correct |
5 |
Correct |
33 ms |
9600 KB |
Output is correct |
6 |
Correct |
33 ms |
9856 KB |
Output is correct |
7 |
Correct |
35 ms |
9976 KB |
Output is correct |
8 |
Correct |
36 ms |
9984 KB |
Output is correct |
9 |
Correct |
48 ms |
10368 KB |
Output is correct |
10 |
Correct |
162 ms |
14460 KB |
Output is correct |
11 |
Correct |
65 ms |
11256 KB |
Output is correct |
12 |
Correct |
93 ms |
12024 KB |
Output is correct |
13 |
Correct |
83 ms |
11640 KB |
Output is correct |
14 |
Correct |
57 ms |
11000 KB |
Output is correct |
15 |
Correct |
85 ms |
12024 KB |
Output is correct |
16 |
Correct |
88 ms |
12280 KB |
Output is correct |
17 |
Correct |
82 ms |
11768 KB |
Output is correct |
18 |
Correct |
104 ms |
11932 KB |
Output is correct |
19 |
Correct |
119 ms |
13048 KB |
Output is correct |
20 |
Correct |
204 ms |
15736 KB |
Output is correct |
21 |
Correct |
120 ms |
13432 KB |
Output is correct |
22 |
Correct |
122 ms |
13048 KB |
Output is correct |
23 |
Correct |
116 ms |
13308 KB |
Output is correct |
24 |
Correct |
119 ms |
13304 KB |
Output is correct |
25 |
Correct |
114 ms |
13048 KB |
Output is correct |
26 |
Correct |
109 ms |
12920 KB |
Output is correct |
27 |
Correct |
129 ms |
13432 KB |
Output is correct |
28 |
Correct |
142 ms |
13432 KB |
Output is correct |
29 |
Correct |
161 ms |
14200 KB |
Output is correct |
30 |
Correct |
229 ms |
16368 KB |
Output is correct |
31 |
Correct |
145 ms |
14200 KB |
Output is correct |
32 |
Correct |
140 ms |
13428 KB |
Output is correct |
33 |
Correct |
131 ms |
13560 KB |
Output is correct |
34 |
Correct |
156 ms |
13832 KB |
Output is correct |
35 |
Correct |
124 ms |
13560 KB |
Output is correct |
36 |
Correct |
125 ms |
13816 KB |
Output is correct |
37 |
Correct |
165 ms |
14328 KB |
Output is correct |
38 |
Correct |
165 ms |
14072 KB |
Output is correct |
39 |
Correct |
184 ms |
14200 KB |
Output is correct |
40 |
Correct |
212 ms |
15740 KB |
Output is correct |
41 |
Correct |
300 ms |
18040 KB |
Output is correct |