Submission #380242

# Submission time Handle Problem Language Result Execution time Memory
380242 2021-03-20T16:47:05 Z rqi Airline Route Map (JOI18_airline) C++14
37 / 100
808 ms 27736 KB
#include "Alicelib.h"
#include <cassert>
#include <cstdio>
#include <bits/stdc++.h>
using namespace std;

typedef pair<int, int> pi;
typedef vector<pi> vpi;

#define mp make_pair
#define f first
#define s second
#define pb push_back

#define sz(x) (int)(x).size()

static vpi eds;
static int deg[1505];

void Alice( int N, int M, int A[], int B[]){
	eds.clear();
	for(int i = 0; i < 1505; i++){
		deg[i] = 0;
	}

	for(int i = 0; i < M; i++){
		eds.pb(mp(A[i], B[i]));
	}
	for(int i = 0; i < N; i++){
		for(int j = 0; j < 10; j++){
			if((i>>j)&1){
				eds.pb(mp(i, N+j));
			}
		}
	}

	vpi tree_eds = vpi{mp(0, 1), mp(0, 2), mp(2, 3), mp(0, 4), mp(4, 5), mp(5, 6), mp(6, 7), mp(7, 8), mp(8, 9)};

	for(auto u: tree_eds){
		eds.pb(mp(N+u.f, N+u.s));
	}

	// for(int j = 0; j < 10; j++){
	// 	eds.pb(mp(N+j, N+11));
	// }

	for(auto u: eds){
		deg[u.f]++;
		deg[u.s]++;
	}

	for(int i = 0; i < N+10; i++){
		if((deg[i] % 3 == 1)^((i >= N)&(i <= N+9))){
			eds.pb(mp(i, N+10));
		}
	}

	InitG(N+11, sz(eds));

	// cout << "nodes: " << N+12 << "\n";
	// cout << "Actual graph: " << "\n";
	for(int i = 0; i < sz(eds); i++){
		MakeG(i, eds[i].f, eds[i].s);
		// cout << eds[i].f << " " << eds[i].s << "\n";
	}
}

#include "Boblib.h"
#include <cassert>
#include <cstdio>
#include <bits/stdc++.h>
using namespace std;

typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vpi;

#define mp make_pair
#define f first
#define s second
#define pb push_back
#define all(x) begin(x), end(x)

#define sz(x) (int)(x).size()

static bool adj[1505][1505];
static int deg[1505];
static int original_ind[1505];
static bool pres[1505];
static vi small_adj[10];

static vi checkSmall(vpi small_eds){
	// cout << "checkSmall(";
	// for(auto u: small_eds){
	// 	cout << u.f << " " << u.s << "\n";
	// }
	// cout << ")" << "\n";

	if(sz(small_eds) != 9) return vi{};
	for(auto u: small_eds){
		assert(0 <= u.f && u.s <= 9);
	}

	int cen = -1;
	for(int i = 0; i < 10; i++){
		small_adj[i].clear();
	}
	for(auto u: small_eds){
		small_adj[u.f].pb(u.s);
		small_adj[u.s].pb(u.f);
	}

	for(int i = 0; i < 10; i++){
		if(sz(small_adj[i]) == 3){
			if(cen == -1){
				cen = i;
			}
			else{
				cen = -2;
			}
		}
	}

	if(cen < 0) return vi{};

	//cout << "cen: " << cen << "\n";

	vector<pair<int, vi>> branches;

	bool works = 1;
	for(auto node: small_adj[cen]){
		vi branch;
		int last_node = cen;
		while(true){
			if(node == cen){ //cycle
				works = 0;
				break;
			}

			branch.pb(node);
			if(sz(small_adj[node]) == 1) break;
			if(sz(small_adj[node]) != 2){
				works = 0;
				break;
			}

			if(small_adj[node][0] == last_node){
				last_node = node;
				node = small_adj[node][1];
			}
			else{
				last_node = node;
				node = small_adj[node][0];
			}
		}

		branches.pb(mp(sz(branch), branch));

		if(!works) break;
	}
	if(!works) return vi{};
	
	sort(all(branches));
	if(sz(branches) != 3 || branches[0].f != 1 || branches[1].f != 2 || branches[2].f != 6) return vi{};

	vi res(10, 0);
	res[0] = cen;
	int cur = 0;
	for(auto &u: branches){
		for(auto &x: u.s){
			res[++cur] = x;
		}
	}

	// cout << "res: ";
	// for(auto u: res){
	// 	cout << u << " ";
	// }
	// cout << "\n";
	return res;
}

void Bob( int V, int U, int C[], int D[] ){
	for(int i = 0; i < 1505; i++){
		for(int j = 0; j < 1505; j++){
			adj[i][j] = 0;
		}
	}
	for(int i = 0; i < 1505; i++){
		deg[i] = 0;
		original_ind[i] = 0;
	}

	int N = V-11;

	//cout << "encrypted graph: " << "\n";
	for(int i = 0; i < U; i++){
		adj[C[i]][D[i]] = 1;
		adj[D[i]][C[i]] = 1;
		deg[C[i]]++; deg[D[i]]++;
		//cout << C[i] << " " << D[i] << "\n";
	}

	vector<pair<int, vi>> bin_cands;

	for(int spec_node = 0; spec_node < V; spec_node++){
		vi dif_nodes;

		for(int i = 0; i < V; i++){
			if(spec_node == i) continue;
			if(adj[i][spec_node]){
				deg[i]--;
			}
		}

		for(int i = 0; i < V; i++){
			if(spec_node == i) continue;
			bool is_dif = 0;
			if(adj[i][spec_node]){
				is_dif^=1;
			}
			if(deg[i] % 3 == 1){
				is_dif^=1;
			}

			if(is_dif){
				dif_nodes.pb(i);
			}
		}

		for(int i = 0; i < V; i++){
			if(spec_node == i) continue;
			if(adj[i][spec_node]){
				deg[i]++;
			}
		}

		if(sz(dif_nodes) == 10){
			bin_cands.pb(mp(spec_node, dif_nodes));
		}
	}

	vpi ans;

	for(auto x: bin_cands){
		//cout << "spec node: " << x.f << "\n";
		vi bins = x.s;
		// cout << "bins: " << "\n";
		// for(auto u: bins){
		// 	cout << u << " ";
		// }
		// cout << "\n";
		vpi small_eds;
		for(int i = 0; i < sz(bins); i++){
			for(int j = i+1; j < sz(bins); j++){
				if(adj[bins[i]][bins[j]]){
					small_eds.pb(mp(i, j));
				}
			}
		}



		vi res = checkSmall(small_eds); //bins[res[i]] is original node N+i

		if(sz(res) == 0) continue;


		// int add_node = -1;
		// for(int i = 0; i < V; i++){
		// 	if(i == x.f) continue;

			
		// 	bool is_add_node = 1;

		// 	for(int j = 0; j < 10; j++){
		// 		if(bins[j] == i){
		// 			is_add_node = 0;
		// 			break;
		// 		}
		// 		if(!adj[i][bins[j]]){
		// 			is_add_node = 0;
		// 			break;
		// 		}
		// 	}

		// 	if(adj[x.f][i]) deg[i]--;
		// 	if(deg[i] != 10){
		// 		is_add_node = 0;
		// 	}
		// 	if(adj[x.f][i]) deg[i]++;
			
		// 	if(is_add_node){
		// 		if(add_node == -1){
		// 			add_node = i;
		// 		}
		// 		else{
		// 			add_node = -2;
		// 		}
		// 	}
		// }
		// if(add_node < 0){
		// 	continue;
		// }

		for(int i = 0; i < V; i++){
			original_ind[i] = 0;
		}

		for(int i = 0; i < 10; i++){
			for(int j = 0; j < V; j++){
				if(adj[bins[res[i]]][j]){
					original_ind[j]+=(1<<i);
				}
			}
		}
		original_ind[x.f] = -1;
		for(auto u: bins){
			original_ind[u] = -1;
		}

		for(int i = 0; i < N; i++){
			pres[i] = 0;
		}

		for(int i = 0; i < V; i++){
			if(original_ind[i] == -1) continue;
			if(0 <= original_ind[i] && original_ind[i] < N){
				pres[original_ind[i]] = 1;
			}
		}

		bool works = 1;
		for(int i = 0; i < N; i++){
			if(!pres[i]){
				works = 0;
				break;
			}
		}
		if(!works) continue;

		//cout << "FOUND CANDIDATE" << "\n";
		for(int i = 0; i < V; i++){
			for(int j = i+1; j < V; j++){
				if(original_ind[i] >= 0 && original_ind[j] >= 0){
					if(adj[i][j]){
						ans.pb(mp(original_ind[i], original_ind[j]));
					}
				}
			}
		}
		break;
	}

	InitMap(V-11, sz(ans));
	for(auto u: ans){
		MakeMap(u.f, u.s);
	}
}

# Verdict Execution time Memory Grader output
1 Correct 8 ms 7224 KB Output is correct
2 Correct 8 ms 6960 KB Output is correct
3 Correct 8 ms 7136 KB Output is correct
4 Correct 9 ms 7008 KB Output is correct
5 Correct 8 ms 7136 KB Output is correct
6 Correct 8 ms 7136 KB Output is correct
7 Correct 8 ms 7216 KB Output is correct
8 Correct 8 ms 7008 KB Output is correct
9 Correct 8 ms 7136 KB Output is correct
10 Correct 8 ms 7136 KB Output is correct
11 Correct 9 ms 7136 KB Output is correct
12 Correct 7 ms 7008 KB Output is correct
13 Correct 7 ms 7008 KB Output is correct
14 Correct 8 ms 7136 KB Output is correct
15 Correct 8 ms 7008 KB Output is correct
16 Correct 8 ms 7008 KB Output is correct
17 Correct 9 ms 7224 KB Output is correct
18 Correct 8 ms 7008 KB Output is correct
19 Correct 8 ms 7136 KB Output is correct
20 Correct 8 ms 7224 KB Output is correct
21 Correct 8 ms 7136 KB Output is correct
22 Correct 9 ms 7228 KB Output is correct
23 Correct 8 ms 7008 KB Output is correct
24 Correct 7 ms 7008 KB Output is correct
25 Correct 8 ms 7136 KB Output is correct
26 Correct 8 ms 7232 KB Output is correct
27 Correct 9 ms 7228 KB Output is correct
28 Correct 8 ms 7008 KB Output is correct
29 Correct 8 ms 7136 KB Output is correct
30 Correct 8 ms 7136 KB Output is correct
31 Correct 8 ms 7008 KB Output is correct
32 Correct 7 ms 7136 KB Output is correct
33 Correct 7 ms 7136 KB Output is correct
34 Correct 8 ms 7008 KB Output is correct
35 Correct 9 ms 7232 KB Output is correct
36 Correct 8 ms 7136 KB Output is correct
37 Correct 7 ms 7008 KB Output is correct
38 Correct 7 ms 7216 KB Output is correct
39 Correct 8 ms 7136 KB Output is correct
40 Correct 9 ms 7084 KB Output is correct
41 Correct 8 ms 7008 KB Output is correct
42 Correct 9 ms 7224 KB Output is correct
43 Correct 8 ms 7136 KB Output is correct
44 Correct 9 ms 7232 KB Output is correct
45 Correct 9 ms 7136 KB Output is correct
46 Correct 8 ms 7224 KB Output is correct
47 Correct 8 ms 7008 KB Output is correct
48 Correct 8 ms 7136 KB Output is correct
49 Correct 9 ms 7136 KB Output is correct
50 Correct 8 ms 7068 KB Output is correct
51 Correct 7 ms 7240 KB Output is correct
52 Correct 7 ms 7008 KB Output is correct
53 Correct 8 ms 7240 KB Output is correct
54 Correct 7 ms 7008 KB Output is correct
55 Correct 8 ms 7224 KB Output is correct
56 Correct 7 ms 7008 KB Output is correct
57 Correct 8 ms 7224 KB Output is correct
58 Correct 9 ms 7376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 7224 KB Output is correct
2 Correct 8 ms 6960 KB Output is correct
3 Correct 8 ms 7136 KB Output is correct
4 Correct 9 ms 7008 KB Output is correct
5 Correct 8 ms 7136 KB Output is correct
6 Correct 8 ms 7136 KB Output is correct
7 Correct 8 ms 7216 KB Output is correct
8 Correct 8 ms 7008 KB Output is correct
9 Correct 8 ms 7136 KB Output is correct
10 Correct 8 ms 7136 KB Output is correct
11 Correct 9 ms 7136 KB Output is correct
12 Correct 7 ms 7008 KB Output is correct
13 Correct 7 ms 7008 KB Output is correct
14 Correct 8 ms 7136 KB Output is correct
15 Correct 8 ms 7008 KB Output is correct
16 Correct 8 ms 7008 KB Output is correct
17 Correct 9 ms 7224 KB Output is correct
18 Correct 8 ms 7008 KB Output is correct
19 Correct 8 ms 7136 KB Output is correct
20 Correct 8 ms 7224 KB Output is correct
21 Correct 8 ms 7136 KB Output is correct
22 Correct 9 ms 7228 KB Output is correct
23 Correct 8 ms 7008 KB Output is correct
24 Correct 7 ms 7008 KB Output is correct
25 Correct 8 ms 7136 KB Output is correct
26 Correct 8 ms 7232 KB Output is correct
27 Correct 9 ms 7228 KB Output is correct
28 Correct 8 ms 7008 KB Output is correct
29 Correct 8 ms 7136 KB Output is correct
30 Correct 8 ms 7136 KB Output is correct
31 Correct 8 ms 7008 KB Output is correct
32 Correct 7 ms 7136 KB Output is correct
33 Correct 7 ms 7136 KB Output is correct
34 Correct 8 ms 7008 KB Output is correct
35 Correct 9 ms 7232 KB Output is correct
36 Correct 8 ms 7136 KB Output is correct
37 Correct 7 ms 7008 KB Output is correct
38 Correct 7 ms 7216 KB Output is correct
39 Correct 8 ms 7136 KB Output is correct
40 Correct 9 ms 7084 KB Output is correct
41 Correct 8 ms 7008 KB Output is correct
42 Correct 9 ms 7224 KB Output is correct
43 Correct 8 ms 7136 KB Output is correct
44 Correct 9 ms 7232 KB Output is correct
45 Correct 9 ms 7136 KB Output is correct
46 Correct 8 ms 7224 KB Output is correct
47 Correct 8 ms 7008 KB Output is correct
48 Correct 8 ms 7136 KB Output is correct
49 Correct 9 ms 7136 KB Output is correct
50 Correct 8 ms 7068 KB Output is correct
51 Correct 7 ms 7240 KB Output is correct
52 Correct 7 ms 7008 KB Output is correct
53 Correct 8 ms 7240 KB Output is correct
54 Correct 7 ms 7008 KB Output is correct
55 Correct 8 ms 7224 KB Output is correct
56 Correct 7 ms 7008 KB Output is correct
57 Correct 8 ms 7224 KB Output is correct
58 Correct 9 ms 7376 KB Output is correct
59 Correct 9 ms 7248 KB Output is correct
60 Correct 9 ms 7212 KB Output is correct
61 Correct 8 ms 7136 KB Output is correct
62 Correct 7 ms 7008 KB Output is correct
63 Correct 8 ms 7340 KB Output is correct
64 Correct 10 ms 7136 KB Output is correct
65 Correct 9 ms 7200 KB Output is correct
66 Correct 10 ms 7212 KB Output is correct
67 Correct 9 ms 7136 KB Output is correct
68 Correct 8 ms 7224 KB Output is correct
69 Correct 8 ms 7008 KB Output is correct
70 Correct 11 ms 7136 KB Output is correct
71 Correct 10 ms 7008 KB Output is correct
72 Correct 8 ms 7136 KB Output is correct
73 Correct 9 ms 7212 KB Output is correct
74 Correct 8 ms 7136 KB Output is correct
75 Correct 8 ms 7228 KB Output is correct
76 Correct 8 ms 7264 KB Output is correct
77 Correct 9 ms 7136 KB Output is correct
78 Correct 9 ms 7136 KB Output is correct
79 Correct 9 ms 7008 KB Output is correct
80 Correct 8 ms 7208 KB Output is correct
81 Correct 8 ms 7220 KB Output is correct
82 Correct 8 ms 7008 KB Output is correct
83 Correct 7 ms 7224 KB Output is correct
84 Correct 8 ms 7008 KB Output is correct
85 Correct 9 ms 7008 KB Output is correct
86 Correct 8 ms 7136 KB Output is correct
87 Correct 9 ms 7264 KB Output is correct
88 Correct 11 ms 7136 KB Output is correct
89 Correct 8 ms 7008 KB Output is correct
90 Correct 8 ms 7136 KB Output is correct
91 Correct 8 ms 7264 KB Output is correct
92 Correct 8 ms 7136 KB Output is correct
93 Correct 9 ms 7008 KB Output is correct
94 Correct 9 ms 7084 KB Output is correct
95 Correct 8 ms 7136 KB Output is correct
96 Correct 8 ms 7008 KB Output is correct
97 Correct 9 ms 7136 KB Output is correct
98 Correct 9 ms 7200 KB Output is correct
99 Correct 10 ms 7344 KB Output is correct
100 Correct 9 ms 7136 KB Output is correct
101 Correct 8 ms 7136 KB Output is correct
102 Correct 8 ms 7008 KB Output is correct
103 Correct 8 ms 7008 KB Output is correct
104 Correct 8 ms 7008 KB Output is correct
105 Correct 8 ms 7208 KB Output is correct
106 Correct 9 ms 7336 KB Output is correct
107 Correct 8 ms 7280 KB Output is correct
108 Correct 8 ms 7136 KB Output is correct
109 Correct 8 ms 7008 KB Output is correct
110 Correct 8 ms 6960 KB Output is correct
111 Correct 9 ms 7136 KB Output is correct
112 Correct 8 ms 7208 KB Output is correct
113 Correct 8 ms 7008 KB Output is correct
114 Correct 8 ms 7008 KB Output is correct
115 Correct 9 ms 7008 KB Output is correct
116 Correct 8 ms 7008 KB Output is correct
117 Correct 8 ms 7008 KB Output is correct
118 Correct 9 ms 7264 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 757 ms 27736 KB Output is correct : V - N = 11
2 Correct 675 ms 23972 KB Output is correct : V - N = 11
3 Correct 238 ms 14284 KB Output is correct : V - N = 11
4 Correct 32 ms 7520 KB Output is correct : V - N = 11
5 Correct 144 ms 11260 KB Output is correct : V - N = 11
6 Correct 611 ms 22008 KB Output is correct : V - N = 11
7 Correct 793 ms 27064 KB Output is correct : V - N = 11
8 Correct 808 ms 25356 KB Output is correct : V - N = 11
9 Correct 385 ms 16284 KB Output is correct : V - N = 11
10 Correct 48 ms 8412 KB Output is correct : V - N = 11
11 Correct 105 ms 9272 KB Output is correct : V - N = 11
12 Correct 386 ms 17416 KB Output is correct : V - N = 11
13 Correct 674 ms 26280 KB Output is correct : V - N = 11
14 Correct 686 ms 26900 KB Output is correct : V - N = 11
15 Correct 416 ms 20600 KB Output is correct : V - N = 11
16 Correct 98 ms 10060 KB Output is correct : V - N = 11
17 Correct 32 ms 8004 KB Output is correct : V - N = 11
18 Correct 264 ms 15256 KB Output is correct : V - N = 11
19 Correct 614 ms 24956 KB Output is correct : V - N = 11
20 Correct 723 ms 27504 KB Output is correct : V - N = 11
21 Correct 180 ms 12676 KB Output is correct : V - N = 11
22 Correct 191 ms 11844 KB Output is correct : V - N = 11
23 Correct 56 ms 9456 KB Output is correct : V - N = 11
24 Correct 13 ms 7136 KB Output is correct : V - N = 11
25 Correct 45 ms 8412 KB Output is correct : V - N = 11
26 Correct 132 ms 11268 KB Output is correct : V - N = 11
27 Correct 190 ms 12564 KB Output is correct : V - N = 11
28 Correct 183 ms 12140 KB Output is correct : V - N = 11
29 Correct 94 ms 9732 KB Output is correct : V - N = 11
30 Correct 17 ms 7760 KB Output is correct : V - N = 11
31 Correct 28 ms 7392 KB Output is correct : V - N = 11
32 Correct 26 ms 7392 KB Output is correct : V - N = 11
33 Incorrect 22 ms 7312 KB Wrong Answer [11]
34 Halted 0 ms 0 KB -