답안 #30010

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
30010 2017-07-21T12:05:41 Z PrOAhMeT 007 (CEOI14_007) C++14
30 / 100
1000 ms 23276 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,dd[MAXN],tmp[MAXN];
bool vis[MAXN];
pii edge[600005];
vector<int> v[MAXN];

inline 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);
			}
		}
	}

}

inline 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",&edge[i].st,&edge[i].nd);
		++dd[edge[i].st];
		++dd[edge[i].nd];
	}
	for(int i=1;i<=n;++i)
		v[i].resize(dd[i]);
	for(int i=0;i<m;++i) {
		x=edge[i].st;
		y=edge[i].nd;
		v[y][tmp[y]++]=x;
		v[x][tmp[x]++]=y;
	}
	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]+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:26: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:41: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:66:6: warning: unused variable 'l' [-Wunused-variable]
  int l=0,r=n,ans=-1,md;
      ^
007.cpp:66:10: warning: unused variable 'r' [-Wunused-variable]
  int l=0,r=n,ans=-1,md;
          ^
007.cpp:66:14: warning: unused variable 'ans' [-Wunused-variable]
  int l=0,r=n,ans=-1,md;
              ^
007.cpp:66:21: warning: unused variable 'md' [-Wunused-variable]
  int l=0,r=n,ans=-1,md;
                     ^
007.cpp:51: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:52: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:54:41: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d",&edge[i].st,&edge[i].nd);
                                         ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 16280 KB Output is correct
2 Correct 3 ms 16280 KB Output is correct
3 Correct 0 ms 16280 KB Output is correct
4 Correct 3 ms 16280 KB Output is correct
5 Correct 0 ms 16280 KB Output is correct
6 Correct 0 ms 16280 KB Output is correct
7 Correct 0 ms 16280 KB Output is correct
8 Correct 3 ms 16280 KB Output is correct
9 Correct 0 ms 16280 KB Output is correct
10 Correct 3 ms 16280 KB Output is correct
11 Correct 3 ms 16280 KB Output is correct
12 Correct 0 ms 16280 KB Output is correct
13 Correct 0 ms 16280 KB Output is correct
14 Correct 0 ms 16280 KB Output is correct
15 Correct 0 ms 16280 KB Output is correct
16 Correct 0 ms 16280 KB Output is correct
17 Correct 0 ms 16280 KB Output is correct
18 Correct 0 ms 16280 KB Output is correct
19 Correct 0 ms 16280 KB Output is correct
20 Correct 0 ms 16280 KB Output is correct
21 Correct 3 ms 16280 KB Output is correct
22 Correct 0 ms 16280 KB Output is correct
23 Correct 3 ms 16280 KB Output is correct
24 Correct 0 ms 16280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 17600 KB Output is correct
2 Correct 26 ms 18128 KB Output is correct
3 Correct 16 ms 17600 KB Output is correct
4 Correct 43 ms 18260 KB Output is correct
5 Correct 26 ms 17468 KB Output is correct
6 Correct 19 ms 17732 KB Output is correct
7 Correct 23 ms 17864 KB Output is correct
8 Correct 26 ms 17864 KB Output is correct
9 Execution timed out 1000 ms 17864 KB Execution timed out
10 Execution timed out 1000 ms 20768 KB Execution timed out
11 Correct 56 ms 19184 KB Output is correct
12 Correct 96 ms 19844 KB Output is correct
13 Correct 69 ms 19316 KB Output is correct
14 Correct 46 ms 18920 KB Output is correct
15 Correct 99 ms 19976 KB Output is correct
16 Correct 123 ms 20108 KB Output is correct
17 Correct 129 ms 19712 KB Output is correct
18 Correct 93 ms 19712 KB Output is correct
19 Execution timed out 1000 ms 19844 KB Execution timed out
20 Execution timed out 1000 ms 21560 KB Execution timed out
21 Correct 193 ms 21432 KB Output is correct
22 Correct 146 ms 20636 KB Output is correct
23 Correct 206 ms 21296 KB Output is correct
24 Correct 203 ms 21200 KB Output is correct
25 Correct 159 ms 20900 KB Output is correct
26 Correct 156 ms 20636 KB Output is correct
27 Correct 199 ms 21296 KB Output is correct
28 Correct 223 ms 21296 KB Output is correct
29 Execution timed out 1000 ms 20768 KB Execution timed out
30 Execution timed out 1000 ms 21956 KB Execution timed out
31 Correct 309 ms 22268 KB Output is correct
32 Correct 249 ms 21296 KB Output is correct
33 Correct 229 ms 21428 KB Output is correct
34 Correct 289 ms 21692 KB Output is correct
35 Correct 309 ms 21600 KB Output is correct
36 Correct 283 ms 21880 KB Output is correct
37 Correct 293 ms 22352 KB Output is correct
38 Correct 303 ms 22220 KB Output is correct
39 Correct 316 ms 22220 KB Output is correct
40 Execution timed out 1000 ms 22088 KB Execution timed out
41 Execution timed out 1000 ms 23276 KB Execution timed out