# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
29978 | 2017-07-21T11:35:34 Z | PrOAhMeT | 007 (CEOI14_007) | C++14 | 1000 ms | 20516 KB |
#include <bits/stdc++.h> #define mp make_pair #define pb push_back #define pii pair<int,int> #define LL long long #define st first #define nd second #define endl '\n' using namespace std; const int MAXN=200005; int n,m,dis[4][MAXN],s,d,a,b,t,tt,vis[MAXN]; vector<int> v[MAXN]; void bfs(int start,int wait,int u) { memset(dis[u],-1,sizeof dis[u]); queue<int> q; dis[u][start]=0; int x,y; q.push(start); while(!q.empty()) { x=q.front(); q.pop(); for(int i=0;i<v[x].size();++i) { y=v[x][i]; if(dis[u][y]==-1) { dis[u][y]=dis[u][x]+1; q.push(y); } } } } void go(int x,int d1,int d2) { vis[x]=1; for(int i=0;i<v[x].size();++i) { int y=v[x][i]; if(dis[d1][y]<dis[d1][x]&&dis[d2][y]<dis[d1][x]) go(y,d1,d2); } } int main() { scanf("%d %d",&n,&m); scanf("%d %d %d %d",&s,&d,&a,&b); for(int i=0;i<m;++i) { scanf("%d %d",&t,&tt); v[t].pb(tt); v[tt].pb(t); } int l=0,r=n,ans=-1,md; bfs(d,0,1); bfs(s,0,0); bfs(a,0,2); bfs(b,0,3); if(dis[0][a]>dis[1][a]||dis[0][b]>dis[1][b]) cout<<-1<<endl; else if(!((dis[1][a]-dis[0][a]==dis[1][b]-dis[0][b])&&dis[0][a]==dis[0][b])){ cout<<min(dis[1][a]-dis[0][a],dis[1][b]-dis[0][b])<<endl; } else { go(s,2,3); if(vis[a]==0) { memset(vis,0,sizeof vis); go(s,3,2); if(vis[b]==0) cout<<dis[1][a]-dis[0][a]-1<<endl; else cout<<dis[1][a]-dis[0][a]<<endl; } else cout<<dis[1][a]-dis[0][a]<<endl; } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 10616 KB | Output is correct |
2 | Correct | 3 ms | 10616 KB | Output is correct |
3 | Partially correct | 6 ms | 10616 KB | Partially correct |
4 | Correct | 3 ms | 10616 KB | Output is correct |
5 | Correct | 3 ms | 10616 KB | Output is correct |
6 | Partially correct | 3 ms | 10616 KB | Partially correct |
7 | Partially correct | 3 ms | 10616 KB | Partially correct |
8 | Correct | 3 ms | 10616 KB | Output is correct |
9 | Partially correct | 0 ms | 10616 KB | Partially correct |
10 | Correct | 0 ms | 10616 KB | Output is correct |
11 | Correct | 0 ms | 10616 KB | Output is correct |
12 | Correct | 0 ms | 10616 KB | Output is correct |
13 | Partially correct | 3 ms | 10616 KB | Partially correct |
14 | Correct | 0 ms | 10616 KB | Output is correct |
15 | Partially correct | 0 ms | 10616 KB | Partially correct |
16 | Correct | 6 ms | 10616 KB | Output is correct |
17 | Correct | 3 ms | 10616 KB | Output is correct |
18 | Correct | 0 ms | 10616 KB | Output is correct |
19 | Partially correct | 3 ms | 10616 KB | Partially correct |
20 | Partially correct | 0 ms | 10616 KB | Partially correct |
21 | Correct | 0 ms | 10616 KB | Output is correct |
22 | Partially correct | 0 ms | 10616 KB | Partially correct |
23 | Partially correct | 0 ms | 10616 KB | Partially correct |
24 | Correct | 0 ms | 10616 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Partially correct | 39 ms | 11936 KB | Partially correct |
2 | Correct | 56 ms | 12568 KB | Output is correct |
3 | Partially correct | 46 ms | 11936 KB | Partially correct |
4 | Correct | 66 ms | 12688 KB | Output is correct |
5 | Correct | 56 ms | 11804 KB | Output is correct |
6 | Correct | 29 ms | 12068 KB | Output is correct |
7 | Partially correct | 43 ms | 12200 KB | Partially correct |
8 | Partially correct | 39 ms | 12200 KB | Partially correct |
9 | Execution timed out | 1000 ms | 12596 KB | Execution timed out |
10 | Execution timed out | 1000 ms | 16820 KB | Execution timed out |
11 | Correct | 96 ms | 13520 KB | Output is correct |
12 | Partially correct | 119 ms | 14180 KB | Partially correct |
13 | Correct | 99 ms | 13652 KB | Output is correct |
14 | Correct | 63 ms | 13256 KB | Output is correct |
15 | Partially correct | 103 ms | 14312 KB | Partially correct |
16 | Correct | 106 ms | 14444 KB | Output is correct |
17 | Partially correct | 103 ms | 14048 KB | Partially correct |
18 | Correct | 116 ms | 14048 KB | Output is correct |
19 | Execution timed out | 1000 ms | 15236 KB | Execution timed out |
20 | Execution timed out | 1000 ms | 18008 KB | Execution timed out |
21 | Correct | 149 ms | 16060 KB | Output is correct |
22 | Partially correct | 126 ms | 14972 KB | Partially correct |
23 | Correct | 139 ms | 15632 KB | Output is correct |
24 | Partially correct | 136 ms | 15836 KB | Partially correct |
25 | Correct | 126 ms | 15236 KB | Output is correct |
26 | Correct | 116 ms | 14972 KB | Output is correct |
27 | Partially correct | 149 ms | 15632 KB | Partially correct |
28 | Partially correct | 206 ms | 15632 KB | Partially correct |
29 | Execution timed out | 1000 ms | 16424 KB | Execution timed out |
30 | Execution timed out | 1000 ms | 18536 KB | Execution timed out |
31 | Correct | 193 ms | 17112 KB | Output is correct |
32 | Partially correct | 206 ms | 15632 KB | Partially correct |
33 | Correct | 209 ms | 15764 KB | Output is correct |
34 | Correct | 239 ms | 16028 KB | Output is correct |
35 | Correct | 179 ms | 16156 KB | Output is correct |
36 | Correct | 219 ms | 16832 KB | Output is correct |
37 | Correct | 226 ms | 16688 KB | Output is correct |
38 | Partially correct | 213 ms | 16556 KB | Partially correct |
39 | Partially correct | 256 ms | 16556 KB | Partially correct |
40 | Execution timed out | 1000 ms | 18272 KB | Execution timed out |
41 | Execution timed out | 1000 ms | 20516 KB | Execution timed out |