Submission #110786

# Submission time Handle Problem Language Result Execution time Memory
110786 2019-05-12T08:20:08 Z ckodser 007 (CEOI14_007) C++14
0 / 100
490 ms 26488 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{
	exit(1);
	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]);
	    }
	}
	if(fs[a]!=fs[b]){
	}else{
	    exit(1);
	}

	
    }	
}
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5248 KB Output is correct
2 Correct 5 ms 5248 KB Output is correct
3 Runtime error 5 ms 5248 KB Execution failed because the return code was nonzero
4 Runtime error 7 ms 5248 KB Execution failed because the return code was nonzero
5 Runtime error 6 ms 5248 KB Execution failed because the return code was nonzero
6 Runtime error 6 ms 5324 KB Execution failed because the return code was nonzero
7 Runtime error 6 ms 5248 KB Execution failed because the return code was nonzero
8 Runtime error 6 ms 5248 KB Execution failed because the return code was nonzero
9 Runtime error 6 ms 5248 KB Execution failed because the return code was nonzero
10 Correct 7 ms 5248 KB Output is correct
11 Correct 2 ms 5248 KB Output is correct
12 Runtime error 7 ms 5248 KB Execution failed because the return code was nonzero
13 Runtime error 7 ms 5376 KB Execution failed because the return code was nonzero
14 Runtime error 8 ms 5248 KB Execution failed because the return code was nonzero
15 Runtime error 7 ms 5376 KB Execution failed because the return code was nonzero
16 Runtime error 8 ms 5248 KB Execution failed because the return code was nonzero
17 Runtime error 9 ms 5252 KB Execution failed because the return code was nonzero
18 Runtime error 7 ms 5248 KB Execution failed because the return code was nonzero
19 Runtime error 8 ms 5248 KB Execution failed because the return code was nonzero
20 Runtime error 9 ms 5420 KB Execution failed because the return code was nonzero
21 Correct 8 ms 5248 KB Output is correct
22 Runtime error 8 ms 5376 KB Execution failed because the return code was nonzero
23 Runtime error 7 ms 5376 KB Execution failed because the return code was nonzero
24 Runtime error 9 ms 5376 KB Execution failed because the return code was nonzero
# Verdict Execution time Memory Grader output
1 Runtime error 35 ms 7808 KB Execution failed because the return code was nonzero
2 Runtime error 51 ms 8952 KB Execution failed because the return code was nonzero
3 Runtime error 41 ms 8056 KB Execution failed because the return code was nonzero
4 Runtime error 38 ms 9080 KB Execution failed because the return code was nonzero
5 Correct 37 ms 7800 KB Output is correct
6 Correct 38 ms 8064 KB Output is correct
7 Runtime error 47 ms 8432 KB Execution failed because the return code was nonzero
8 Runtime error 45 ms 8440 KB Execution failed because the return code was nonzero
9 Runtime error 104 ms 9592 KB Execution failed because the return code was nonzero
10 Runtime error 231 ms 18464 KB Execution failed because the return code was nonzero
11 Runtime error 87 ms 11000 KB Execution failed because the return code was nonzero
12 Runtime error 133 ms 12720 KB Execution failed because the return code was nonzero
13 Runtime error 93 ms 11512 KB Execution failed because the return code was nonzero
14 Runtime error 55 ms 10532 KB Execution failed because the return code was nonzero
15 Runtime error 105 ms 12536 KB Execution failed because the return code was nonzero
16 Correct 111 ms 13080 KB Output is correct
17 Runtime error 84 ms 12152 KB Execution failed because the return code was nonzero
18 Runtime error 101 ms 12228 KB Execution failed because the return code was nonzero
19 Runtime error 148 ms 15116 KB Execution failed because the return code was nonzero
20 Runtime error 293 ms 21184 KB Execution failed because the return code was nonzero
21 Runtime error 187 ms 15352 KB Execution failed because the return code was nonzero
22 Runtime error 156 ms 14088 KB Execution failed because the return code was nonzero
23 Correct 176 ms 15184 KB Output is correct
24 Runtime error 188 ms 15068 KB Execution failed because the return code was nonzero
25 Runtime error 176 ms 14712 KB Execution failed because the return code was nonzero
26 Correct 156 ms 14172 KB Output is correct
27 Runtime error 173 ms 15264 KB Execution failed because the return code was nonzero
28 Runtime error 237 ms 15324 KB Execution failed because the return code was nonzero
29 Runtime error 239 ms 17632 KB Execution failed because the return code was nonzero
30 Runtime error 407 ms 22224 KB Execution failed because the return code was nonzero
31 Runtime error 230 ms 16852 KB Execution failed because the return code was nonzero
32 Runtime error 203 ms 15352 KB Execution failed because the return code was nonzero
33 Correct 186 ms 15608 KB Output is correct
34 Runtime error 263 ms 16236 KB Execution failed because the return code was nonzero
35 Runtime error 150 ms 15608 KB Execution failed because the return code was nonzero
36 Runtime error 215 ms 16008 KB Execution failed because the return code was nonzero
37 Correct 238 ms 17516 KB Output is correct
38 Runtime error 237 ms 17276 KB Execution failed because the return code was nonzero
39 Runtime error 298 ms 17372 KB Execution failed because the return code was nonzero
40 Runtime error 341 ms 21624 KB Execution failed because the return code was nonzero
41 Runtime error 490 ms 26488 KB Execution failed because the return code was nonzero