Submission #29999

# Submission time Handle Problem Language Result Execution time Memory
29999 2017-07-21T11:52:33 Z PrOAhMeT 007 (CEOI14_007) C++14
0 / 100
1000 ms 19932 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,x,y,mx,aa,mx1;
bool 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;
	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) {

	vis[x]=1;
	mx=max(mx,dis[aa][x]);
	for(int i=0;i<v[x].size();++i) {
		y=v[x][i];
		if(dis[2][y]<dis[2][x]&&dis[3][y]<dis[3][x])
			go(y);
	}

}

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 {
		aa=0;
		go(s);
		mx1=mx;
		if(vis[a]==0||vis[b]==0) {
			memset(vis,0,sizeof vis);
			mx=0;
			aa=1;
			go(d);
			if(mx<=dis[1][a]-dis[0][a]+1+mx1)
				cout<<dis[1][a]-dis[0][a]<<endl;
			else cout<<dis[1][a]-dis[0][a]-1<<endl;
		}
		else cout<<dis[1][a]-dis[0][a]<<endl;
	}

}

Compilation message

007.cpp: In function 'void bfs(int, int, int)':
007.cpp:25:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=0;i<v[x].size();++i) {
                ^
007.cpp: In function 'void go(int)':
007.cpp:40:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<v[x].size();++i) {
               ^
007.cpp: In function 'int main()':
007.cpp:57:6: warning: unused variable 'l' [-Wunused-variable]
  int l=0,r=n,ans=-1,md;
      ^
007.cpp:57:10: warning: unused variable 'r' [-Wunused-variable]
  int l=0,r=n,ans=-1,md;
          ^
007.cpp:57:14: warning: unused variable 'ans' [-Wunused-variable]
  int l=0,r=n,ans=-1,md;
              ^
007.cpp:57:21: warning: unused variable 'md' [-Wunused-variable]
  int l=0,r=n,ans=-1,md;
                     ^
007.cpp:50:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d",&n,&m);
                      ^
007.cpp:51:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d %d %d",&s,&d,&a,&b);
                                  ^
007.cpp:53:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d",&t,&tt);
                        ^
# Verdict Execution time Memory Grader output
1 Correct 3 ms 10032 KB Output is correct
2 Correct 0 ms 10032 KB Output is correct
3 Correct 3 ms 10032 KB Output is correct
4 Incorrect 3 ms 10032 KB Output isn't correct
5 Incorrect 0 ms 10032 KB Output isn't correct
6 Correct 0 ms 10032 KB Output is correct
7 Correct 0 ms 10032 KB Output is correct
8 Incorrect 0 ms 10032 KB Output isn't correct
9 Correct 6 ms 10032 KB Output is correct
10 Correct 0 ms 10032 KB Output is correct
11 Correct 0 ms 10032 KB Output is correct
12 Incorrect 0 ms 10032 KB Output isn't correct
13 Correct 3 ms 10032 KB Output is correct
14 Correct 6 ms 10032 KB Output is correct
15 Correct 3 ms 10032 KB Output is correct
16 Incorrect 6 ms 10032 KB Output isn't correct
17 Incorrect 3 ms 10032 KB Output isn't correct
18 Incorrect 0 ms 10032 KB Output isn't correct
19 Correct 3 ms 10032 KB Output is correct
20 Correct 3 ms 10032 KB Output is correct
21 Correct 3 ms 10032 KB Output is correct
22 Correct 0 ms 10032 KB Output is correct
23 Correct 6 ms 10032 KB Output is correct
24 Incorrect 3 ms 10032 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 11352 KB Output is correct
2 Incorrect 53 ms 11920 KB Output isn't correct
3 Correct 39 ms 11352 KB Output is correct
4 Incorrect 49 ms 12064 KB Output isn't correct
5 Correct 36 ms 11220 KB Output is correct
6 Correct 29 ms 11484 KB Output is correct
7 Correct 46 ms 11616 KB Output is correct
8 Correct 56 ms 11616 KB Output is correct
9 Execution timed out 1000 ms 12012 KB Execution timed out
10 Execution timed out 1000 ms 16236 KB Execution timed out
11 Incorrect 56 ms 12936 KB Output isn't correct
12 Correct 73 ms 13596 KB Output is correct
13 Incorrect 99 ms 13068 KB Output isn't correct
14 Correct 83 ms 12672 KB Output is correct
15 Correct 116 ms 13728 KB Output is correct
16 Correct 119 ms 13860 KB Output is correct
17 Correct 99 ms 13464 KB Output is correct
18 Correct 106 ms 13464 KB Output is correct
19 Execution timed out 1000 ms 14652 KB Execution timed out
20 Execution timed out 1000 ms 17424 KB Execution timed out
21 Incorrect 129 ms 15396 KB Output isn't correct
22 Correct 166 ms 14388 KB Output is correct
23 Correct 169 ms 15048 KB Output is correct
24 Correct 156 ms 15080 KB Output is correct
25 Incorrect 139 ms 14652 KB Output isn't correct
26 Correct 146 ms 14388 KB Output is correct
27 Correct 199 ms 15048 KB Output is correct
28 Correct 213 ms 15048 KB Output is correct
29 Execution timed out 1000 ms 15840 KB Execution timed out
30 Execution timed out 1000 ms 17952 KB Execution timed out
31 Incorrect 196 ms 16268 KB Output isn't correct
32 Correct 119 ms 15048 KB Output is correct
33 Correct 193 ms 15180 KB Output is correct
34 Incorrect 213 ms 15444 KB Output isn't correct
35 Incorrect 169 ms 15592 KB Output isn't correct
36 Incorrect 189 ms 15884 KB Output isn't correct
37 Correct 216 ms 16104 KB Output is correct
38 Correct 226 ms 15972 KB Output is correct
39 Correct 226 ms 15972 KB Output is correct
40 Execution timed out 1000 ms 17688 KB Execution timed out
41 Execution timed out 1000 ms 19932 KB Execution timed out