답안 #110788

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
110788 2019-05-12T08:25:12 Z ckodser 007 (CEOI14_007) C++14
0 / 100
399 ms 26500 KB
#include<bits/stdc++.h>

#define ll long long
#define pb push_back
#define mp make_pair
#define ld long double
#define F first
#define S second
#define pii pair<ll,ll> 

using namespace :: std;

const ll mod=1e9+7;
const ll maxn=2e5+500;
const ll inf=1e9+900;

vector<ll> ger[maxn];
ll fs[maxn];
ll fd[maxn];
ll fa[maxn];
ll fb[maxn];
bool vis[maxn];

void bfs(ll a,ll* f){
    queue<ll> qu;
    memset(vis,0,sizeof vis);
    qu.push(a);
    vis[a]=1;
    while(qu.size()){
	ll v=qu.front();
	qu.pop();
	for(auto u:ger[v]){
	    if(!vis[u]){
		vis[u]=1;
		f[u]=f[v]+1;
		qu.push(u);
	    }
	}
    }
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll n,m;
    cin>>n>>m;
    ll s,d,a,b;
    cin>>s>>d>>a>>b;
    for(ll i=0;i<m;i++){
	ll a,b;
	cin>>a>>b;
	ger[a].pb(b);
	ger[b].pb(a);
    }
    bfs(s,fs);
    bfs(d,fd);
    bfs(a,fa);
    bfs(b,fb);

    if(fd[a]!=fd[b] || fs[a]!=fs[b]){
	ll r1=fd[a];
	ll r2=fd[b];
	ll w1=fs[a];
	ll w2=fs[b];
	if(r1>r2){
	    swap(r1,r2);
	    swap(w1,w2);
	}	
	ll ans=min(r1-w1,r2-w2);
	if(ans<0){
	    ans=-1;
	}
	cout<<ans<<endl;
    }else{
	ll mxd=0;
	for(ll i=1;i<=n;i++){
	    if(fd[i]+fa[i]==fd[a] && fd[i]+fb[i]==fd[a]){
		mxd=max(mxd,fd[i]);
	    }
	}
	ll mxs=0;
	for(ll i=1;i<=n;i++){
	    if(fs[i]+fa[i]==fs[a] && fs[i]+fb[i]==fs[b]){
		mxs=max(mxs,fs[i]);
	    }
	}
	ll q=mxd;
	ll w=fd[a]-mxd;
	ll e=mxs;
	ll r=fs[a]-mxs;
	ll r1=fd[a];
	ll w1=fs[a];
	ll x=r1-w1;
	cout<<x<<endl;
	
    }	
}

Compilation message

007.cpp: In function 'int main()':
007.cpp:85:5: warning: unused variable 'q' [-Wunused-variable]
  ll q=mxd;
     ^
007.cpp:86:5: warning: unused variable 'w' [-Wunused-variable]
  ll w=fd[a]-mxd;
     ^
007.cpp:87:5: warning: unused variable 'e' [-Wunused-variable]
  ll e=mxs;
     ^
007.cpp:88:5: warning: unused variable 'r' [-Wunused-variable]
  ll r=fs[a]-mxs;
     ^
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 5248 KB Output is correct
2 Correct 8 ms 5248 KB Output is correct
3 Correct 9 ms 5248 KB Output is correct
4 Incorrect 8 ms 5248 KB Output isn't correct
5 Incorrect 8 ms 5248 KB Output isn't correct
6 Correct 7 ms 5248 KB Output is correct
7 Correct 7 ms 5248 KB Output is correct
8 Incorrect 8 ms 5248 KB Output isn't correct
9 Correct 6 ms 5248 KB Output is correct
10 Correct 6 ms 5248 KB Output is correct
11 Correct 7 ms 5248 KB Output is correct
12 Incorrect 6 ms 5376 KB Output isn't correct
13 Correct 6 ms 5376 KB Output is correct
14 Incorrect 6 ms 5248 KB Output isn't correct
15 Correct 6 ms 5248 KB Output is correct
16 Incorrect 6 ms 5348 KB Output isn't correct
17 Incorrect 6 ms 5248 KB Output isn't correct
18 Incorrect 7 ms 5248 KB Output isn't correct
19 Correct 7 ms 5504 KB Output is correct
20 Correct 6 ms 5248 KB Output is correct
21 Correct 6 ms 5376 KB Output is correct
22 Correct 6 ms 5376 KB Output is correct
23 Correct 6 ms 5376 KB Output is correct
24 Incorrect 6 ms 5376 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 7936 KB Output is correct
2 Incorrect 54 ms 8952 KB Output isn't correct
3 Correct 37 ms 8064 KB Output is correct
4 Incorrect 56 ms 9080 KB Output isn't correct
5 Correct 43 ms 7928 KB Output is correct
6 Correct 35 ms 8056 KB Output is correct
7 Correct 67 ms 8452 KB Output is correct
8 Correct 37 ms 8568 KB Output is correct
9 Incorrect 63 ms 9592 KB Output isn't correct
10 Correct 205 ms 18424 KB Output is correct
11 Incorrect 88 ms 11044 KB Output isn't correct
12 Correct 139 ms 12664 KB Output is correct
13 Incorrect 88 ms 11512 KB Output isn't correct
14 Incorrect 75 ms 10488 KB Output isn't correct
15 Correct 116 ms 12664 KB Output is correct
16 Correct 144 ms 12868 KB Output is correct
17 Correct 108 ms 12152 KB Output is correct
18 Incorrect 129 ms 12220 KB Output isn't correct
19 Correct 171 ms 15248 KB Output is correct
20 Incorrect 361 ms 21116 KB Output isn't correct
21 Incorrect 165 ms 15384 KB Output isn't correct
22 Correct 158 ms 14072 KB Output is correct
23 Correct 204 ms 15352 KB Output is correct
24 Correct 157 ms 15096 KB Output is correct
25 Incorrect 136 ms 14656 KB Output isn't correct
26 Correct 131 ms 14200 KB Output is correct
27 Correct 232 ms 15248 KB Output is correct
28 Correct 236 ms 15352 KB Output is correct
29 Correct 184 ms 17656 KB Output is correct
30 Incorrect 371 ms 22364 KB Output isn't correct
31 Incorrect 162 ms 16760 KB Output isn't correct
32 Correct 211 ms 15432 KB Output is correct
33 Correct 180 ms 15596 KB Output is correct
34 Incorrect 185 ms 16248 KB Output isn't correct
35 Incorrect 243 ms 15612 KB Output isn't correct
36 Incorrect 149 ms 15984 KB Output isn't correct
37 Correct 242 ms 17480 KB Output is correct
38 Correct 250 ms 17280 KB Output is correct
39 Correct 327 ms 17272 KB Output is correct
40 Incorrect 317 ms 21592 KB Output isn't correct
41 Correct 399 ms 26500 KB Output is correct