Submission #965986

# Submission time Handle Problem Language Result Execution time Memory
965986 2024-04-19T08:59:13 Z pcc Swapping Cities (APIO20_swap) C++17
37 / 100
2000 ms 19916 KB
#include "swap.h"

#include <vector>
#include <bits/stdc++.h>
using namespace std;

#define pii pair<int,int>
#define fs first
#define sc second

const int mxn = 2e5+10;

vector<int> v;
int N,M;
vector<pair<int,pii>> edges;

void init(int NN, int MM,
          std::vector<int> U, std::vector<int> V, std::vector<int> W) {
	N = NN,M = MM;
	for(int i = 0;i<M;i++){
		edges.push_back(make_pair(W[i],pii(U[i],V[i])));
	}
	sort(edges.begin(),edges.end());
	return;
}

namespace BIS{
	vector<int> paths[mxn];
	int dp[mxn];
	queue<int> q;
	int deg[mxn];

	void bfs(int s,int t,int tag){
		q.push(s);
		dp[s] |= tag;
		while(!q.empty()){
			auto now = q.front();
			q.pop();
			if(now == t)continue;
			for(auto nxt:paths[now]){
				if(dp[nxt]&tag)continue;
				dp[nxt]|=tag;
				q.push(nxt);
			}
		}
		return;
	}

	int cnt[mxn];
	bool check(int id,int s,int t){
		memset(dp,0,sizeof(dp));
		memset(deg,0,sizeof(deg));
		memset(cnt,0,sizeof(cnt));
		for(int i = 0;i<N;i++)paths[i].clear();
		for(int i = 0;i<=min(M-1,id);i++){
			paths[edges[i].sc.fs].push_back(edges[i].sc.sc);
			paths[edges[i].sc.sc].push_back(edges[i].sc.fs);
		}
		bfs(s,N,1);
		if(!dp[t])return false;
		for(int i = 0;i<N;i++){
			if(dp[i]){
				for(auto nxt:paths[i])deg[nxt]++;
			}
		}
		for(int i = 0;i<N;i++){
			if(deg[i])cnt[deg[i]]++;
		}
		if(*max_element(cnt+3,cnt+mxn) == 0&&cnt[1] == 2)return false;
		return true;
	}
}

int getMinimumFuelCapacity(int X, int Y) {
	int l = 0,r = M;
	while(l != r){
		int mid = (l+r)>>1;
		if(BIS::check(mid,X,Y))r = mid;
		else l = mid+1;
		//cout<<X<<' '<<Y<<' '<<edges[mid].fs<<":"<<BIS::check(mid,X,Y)<<endl;
	}
	if(r>=M)return -1;
	return edges[l].fs;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 7260 KB Output is correct
2 Correct 3 ms 7260 KB Output is correct
3 Correct 3 ms 7480 KB Output is correct
4 Correct 6 ms 7260 KB Output is correct
5 Correct 5 ms 7516 KB Output is correct
6 Correct 7 ms 7512 KB Output is correct
7 Correct 5 ms 7516 KB Output is correct
8 Correct 7 ms 7536 KB Output is correct
9 Correct 68 ms 11680 KB Output is correct
10 Correct 132 ms 12740 KB Output is correct
11 Correct 156 ms 12740 KB Output is correct
12 Correct 169 ms 12848 KB Output is correct
13 Correct 210 ms 12776 KB Output is correct
14 Execution timed out 2085 ms 11816 KB Time limit exceeded
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 7260 KB Output is correct
2 Correct 3 ms 7260 KB Output is correct
3 Execution timed out 2013 ms 15580 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 7260 KB Output is correct
2 Correct 3 ms 7260 KB Output is correct
3 Correct 3 ms 7480 KB Output is correct
4 Correct 6 ms 7260 KB Output is correct
5 Correct 5 ms 7516 KB Output is correct
6 Correct 7 ms 7512 KB Output is correct
7 Correct 5 ms 7516 KB Output is correct
8 Correct 7 ms 7536 KB Output is correct
9 Correct 3 ms 7260 KB Output is correct
10 Correct 7 ms 7516 KB Output is correct
11 Correct 6 ms 7516 KB Output is correct
12 Correct 7 ms 7516 KB Output is correct
13 Correct 6 ms 7516 KB Output is correct
14 Correct 8 ms 7768 KB Output is correct
15 Correct 8 ms 7524 KB Output is correct
16 Correct 7 ms 7516 KB Output is correct
17 Correct 8 ms 7516 KB Output is correct
18 Correct 7 ms 7556 KB Output is correct
19 Correct 9 ms 7516 KB Output is correct
20 Correct 7 ms 7768 KB Output is correct
21 Correct 10 ms 7344 KB Output is correct
22 Correct 11 ms 7604 KB Output is correct
23 Correct 9 ms 7516 KB Output is correct
24 Correct 14 ms 7516 KB Output is correct
25 Correct 14 ms 7768 KB Output is correct
26 Correct 10 ms 7516 KB Output is correct
27 Correct 10 ms 7548 KB Output is correct
28 Correct 12 ms 7516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7260 KB Output is correct
2 Correct 2 ms 7260 KB Output is correct
3 Correct 3 ms 7260 KB Output is correct
4 Correct 3 ms 7480 KB Output is correct
5 Correct 6 ms 7260 KB Output is correct
6 Correct 5 ms 7516 KB Output is correct
7 Correct 7 ms 7512 KB Output is correct
8 Correct 5 ms 7516 KB Output is correct
9 Correct 7 ms 7536 KB Output is correct
10 Correct 68 ms 11680 KB Output is correct
11 Correct 132 ms 12740 KB Output is correct
12 Correct 156 ms 12740 KB Output is correct
13 Correct 169 ms 12848 KB Output is correct
14 Correct 210 ms 12776 KB Output is correct
15 Correct 7 ms 7516 KB Output is correct
16 Correct 6 ms 7516 KB Output is correct
17 Correct 7 ms 7516 KB Output is correct
18 Correct 6 ms 7516 KB Output is correct
19 Correct 8 ms 7768 KB Output is correct
20 Correct 8 ms 7524 KB Output is correct
21 Correct 7 ms 7516 KB Output is correct
22 Correct 8 ms 7516 KB Output is correct
23 Correct 7 ms 7556 KB Output is correct
24 Correct 9 ms 7516 KB Output is correct
25 Correct 7 ms 7768 KB Output is correct
26 Correct 10 ms 7344 KB Output is correct
27 Correct 11 ms 7604 KB Output is correct
28 Correct 9 ms 7516 KB Output is correct
29 Correct 14 ms 7516 KB Output is correct
30 Correct 14 ms 7768 KB Output is correct
31 Correct 10 ms 7516 KB Output is correct
32 Correct 10 ms 7548 KB Output is correct
33 Correct 12 ms 7516 KB Output is correct
34 Correct 11 ms 8728 KB Output is correct
35 Correct 158 ms 14788 KB Output is correct
36 Correct 147 ms 14644 KB Output is correct
37 Correct 168 ms 14788 KB Output is correct
38 Correct 185 ms 14680 KB Output is correct
39 Correct 206 ms 14652 KB Output is correct
40 Correct 192 ms 13996 KB Output is correct
41 Correct 183 ms 15064 KB Output is correct
42 Correct 171 ms 14780 KB Output is correct
43 Correct 187 ms 14788 KB Output is correct
44 Correct 235 ms 15112 KB Output is correct
45 Correct 307 ms 16956 KB Output is correct
46 Correct 166 ms 14640 KB Output is correct
47 Correct 214 ms 14964 KB Output is correct
48 Correct 248 ms 15284 KB Output is correct
49 Correct 73 ms 16956 KB Output is correct
50 Correct 77 ms 13956 KB Output is correct
51 Correct 206 ms 15312 KB Output is correct
52 Correct 273 ms 18892 KB Output is correct
53 Correct 235 ms 19916 KB Output is correct
54 Correct 219 ms 19144 KB Output is correct
55 Correct 190 ms 14644 KB Output is correct
56 Correct 392 ms 18420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 7260 KB Output is correct
2 Correct 3 ms 7260 KB Output is correct
3 Correct 3 ms 7480 KB Output is correct
4 Correct 6 ms 7260 KB Output is correct
5 Correct 5 ms 7516 KB Output is correct
6 Correct 7 ms 7512 KB Output is correct
7 Correct 5 ms 7516 KB Output is correct
8 Correct 7 ms 7536 KB Output is correct
9 Correct 68 ms 11680 KB Output is correct
10 Correct 132 ms 12740 KB Output is correct
11 Correct 156 ms 12740 KB Output is correct
12 Correct 169 ms 12848 KB Output is correct
13 Correct 210 ms 12776 KB Output is correct
14 Execution timed out 2085 ms 11816 KB Time limit exceeded
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7260 KB Output is correct
2 Correct 2 ms 7260 KB Output is correct
3 Correct 3 ms 7260 KB Output is correct
4 Correct 3 ms 7480 KB Output is correct
5 Correct 6 ms 7260 KB Output is correct
6 Correct 5 ms 7516 KB Output is correct
7 Correct 7 ms 7512 KB Output is correct
8 Correct 5 ms 7516 KB Output is correct
9 Correct 7 ms 7536 KB Output is correct
10 Correct 68 ms 11680 KB Output is correct
11 Correct 132 ms 12740 KB Output is correct
12 Correct 156 ms 12740 KB Output is correct
13 Correct 169 ms 12848 KB Output is correct
14 Correct 210 ms 12776 KB Output is correct
15 Execution timed out 2085 ms 11816 KB Time limit exceeded
16 Halted 0 ms 0 KB -