Submission #95211

# Submission time Handle Problem Language Result Execution time Memory
95211 2019-01-28T14:57:45 Z hamzqq9 007 (CEOI14_007) C++14
16 / 100
1000 ms 177712 KB
#include<bits/stdc++.h>
#define st first
#define nd second
#define pb push_back
#define ppb pop_back
#define ppf pop_front
#define umax(x,y) x=max(x,y)
#define umin(x,y) x=min(x,y)
#define ll long long
#define ii pair<int,int>
#define iii pair<ii,int>
#define iiii pair<ii,ii>
#define sz(x) ((int) x.size())
#define orta ((bas+son)/2)
#define all(x) x.begin(),x.end()
#define dbgs(x) cerr<<(#x)<<" --> "<<(x)<<" "
#define dbg(x) cerr<<(#x)<<" --> "<<(x)<<endl;getchar()
#define pw(x) (1ll<<(x))
#define inf 1000000000
#define MOD 1000000007
#define N 600005
#define M 1000003
#define LOG 16
#define KOK 650
#define EPS 0.00001
using namespace std;

int n,m,cur,cur0,s1,s2,x,y;
int dis[4][N],vis[N],vdag[2][N],dep[2][N],frb[N],nodes[2][N];
vector<int> v[N],dag[2][N];

void bfs(int start,int ar) {

	queue<ii> q;

	for(int i=1;i<=n;i++) vis[i]=0;

	q.push({start,0});

	while(!q.empty()) {

		ii cur=q.front();

		q.pop();

		if(vis[cur.st]) continue ;

		vis[cur.st]=1;

		dis[ar][cur.st]=cur.nd;

		for(int i:v[cur.st]) {

			q.push({i,cur.nd+1});

		}

	}

}

bool ok(int wait) {

	if(dis[1][s1]<dis[0][s1]+wait || dis[1][s2]<dis[0][s2]+wait) return false;

	return true;

}

void fdag(int node,int w,int val,int ata) {

	if(dis[2][node]!=val || dis[3][node]!=val) return ;

	nodes[w][node]=1;

	dag[w][ata].pb(node);

	for(int i:v[node]) {

		fdag(i,w,val-1,node);

	}

}

int fdep(int node,int w) {

	if(frb[node]) return 0;

	if(vdag[w][node]) return dep[w][node];

	dep[w][node]=1;

	vdag[w][node]=1;

	for(int i:dag[w][node]) {

//		cout<<node<<" "<<i<<"\n";

		umax(dep[w][node],fdep(i,w)+1);

	}

	return dep[w][node];

}

bool ok2(int val) {

	fdag(cur0,0,min(dis[2][cur0],dis[3][cur0]),0);
	fdag(cur,1,min(dis[2][cur],dis[3][cur]),0);

	int dep0=fdep(0,0);
	int dep1=fdep(0,1);

	if(dep1+val>=dep0) return true;

	for(int i=1;i<=n;i++) {

		if(nodes[1][i]) frb[i]=1;

	}

	memset(vdag[0],0,sizeof(vdag[0]));

	int dep0new=fdep(0,0);

	if(dep0new!=dep0) return true;

	return false;

}

int main() {

	//freopen("input.txt","r",stdin);

	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	
	cin>>n>>m;

	cin>>cur>>cur0>>s1>>s2;

	for(int i=1;i<=m;i++) {

		cin>>x>>y;

		v[x].pb(y);
		v[y].pb(x);

	}

	bfs(cur,0);
	bfs(cur0,1);

	int bas=0,son=m;

	while(bas<=son) {

		if(ok(orta)) bas=orta+1;
		else son=orta-1;

	}

	if(son==-1) {

		cout<<-1;

		return 0;

	}

	bfs(s1,2);
	bfs(s2,3);

	if(!ok2(son)) son--;

	cout<<son;

}

# Verdict Execution time Memory Grader output
1 Partially correct 36 ms 45048 KB Partially correct
2 Correct 34 ms 42652 KB Output is correct
3 Correct 36 ms 42744 KB Output is correct
4 Correct 42 ms 45048 KB Output is correct
5 Correct 37 ms 45056 KB Output is correct
6 Correct 36 ms 42744 KB Output is correct
7 Correct 33 ms 42744 KB Output is correct
8 Correct 35 ms 45048 KB Output is correct
9 Correct 34 ms 42644 KB Output is correct
10 Partially correct 42 ms 45048 KB Partially correct
11 Correct 34 ms 42616 KB Output is correct
12 Correct 36 ms 45052 KB Output is correct
13 Correct 34 ms 42744 KB Output is correct
14 Correct 35 ms 45048 KB Output is correct
15 Correct 34 ms 42744 KB Output is correct
16 Correct 39 ms 45176 KB Output is correct
17 Correct 39 ms 45096 KB Output is correct
18 Correct 36 ms 45048 KB Output is correct
19 Correct 33 ms 42744 KB Output is correct
20 Correct 35 ms 42872 KB Output is correct
21 Correct 33 ms 42744 KB Output is correct
22 Correct 33 ms 42744 KB Output is correct
23 Correct 33 ms 42744 KB Output is correct
24 Correct 40 ms 45736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 58 ms 46200 KB Output is correct
2 Correct 75 ms 50424 KB Output is correct
3 Correct 61 ms 46456 KB Output is correct
4 Correct 85 ms 50652 KB Output is correct
5 Correct 67 ms 45176 KB Output is correct
6 Correct 67 ms 45300 KB Output is correct
7 Correct 70 ms 45676 KB Output is correct
8 Correct 70 ms 45816 KB Output is correct
9 Execution timed out 1080 ms 177712 KB Time limit exceeded
10 Execution timed out 1097 ms 92516 KB Time limit exceeded
11 Correct 109 ms 52728 KB Output is correct
12 Correct 135 ms 52316 KB Output is correct
13 Correct 96 ms 53084 KB Output is correct
14 Correct 74 ms 46848 KB Output is correct
15 Correct 107 ms 52948 KB Output is correct
16 Correct 106 ms 49912 KB Output is correct
17 Correct 105 ms 49172 KB Output is correct
18 Correct 126 ms 51960 KB Output is correct
19 Execution timed out 1094 ms 168084 KB Time limit exceeded
20 Execution timed out 1085 ms 100788 KB Time limit exceeded
21 Correct 156 ms 59612 KB Output is correct
22 Correct 192 ms 55104 KB Output is correct
23 Correct 187 ms 51960 KB Output is correct
24 Correct 212 ms 56380 KB Output is correct
25 Correct 194 ms 58104 KB Output is correct
26 Correct 165 ms 51320 KB Output is correct
27 Correct 158 ms 52120 KB Output is correct
28 Correct 152 ms 52428 KB Output is correct
29 Execution timed out 1084 ms 161456 KB Time limit exceeded
30 Execution timed out 1091 ms 102592 KB Time limit exceeded
31 Correct 244 ms 61492 KB Output is correct
32 Correct 225 ms 56312 KB Output is correct
33 Correct 201 ms 52280 KB Output is correct
34 Correct 180 ms 59640 KB Output is correct
35 Correct 214 ms 60152 KB Output is correct
36 Correct 177 ms 60920 KB Output is correct
37 Correct 186 ms 53880 KB Output is correct
38 Correct 181 ms 53624 KB Output is correct
39 Correct 243 ms 53756 KB Output is correct
40 Execution timed out 1071 ms 145924 KB Time limit exceeded
41 Execution timed out 1084 ms 102072 KB Time limit exceeded