Submission #553994

# Submission time Handle Problem Language Result Execution time Memory
553994 2022-04-27T13:46:50 Z nafis_shifat Amusement Park (JOI17_amusement_park) C++14
100 / 100
319 ms 23812 KB
#include "Joi.h"
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
using namespace std;
const int mxn=1e5+5;
const int inf=1e9;

vector<int> g[mxn];
vector<int> adj[mxn];
int n;
int vis[mxn] = {};
const int SZ = 60;
void dfs0(int u) {
	vis[u] = 1;
	for(int v : g[u]) {
		if(vis[v]) continue;
		adj[u].push_back(v);
		adj[v].push_back(u);
		dfs0(v);
	}
}



int bit[mxn] = {};
int group[mxn] = {};
vector<int> con[mxn];

int id = 0;
int done[mxn] = {};


vector<int> dfs(int u, int prev) {

	vector<int> cur;

	cur.push_back(u);
	for(int v : adj[u]) {
		if(v == prev) continue;
		vector<int> x = dfs(v, u);

		for(int i : x) cur.push_back(i);
	}


    if(cur.size() < SZ) return cur;
    id++;
    for(int i = 0; i < SZ; i++) {
    	group[cur[i]] = id;
    	bit[cur[i]] = i;
    	con[id].push_back(cur[i]);
    	done[cur[i]] = 1;
    }

    return {};
}


vector<int> Vis;
void travel(int u, int prev) {
	Vis.push_back(u);
	done[u] = 1;
	for(int v : adj[u]) {
		if(v == prev || done[v]) continue;
		travel(v, u);

	}
}

bool na[mxn] = {};

vector<int> na_con;

void dfs2(int u, int prev) {
	na_con.push_back(u);
	for(int v : adj[u]) {
		if(v == prev || !na[v]) continue;
		dfs2(v, u);
	}
} 

void prc() {
	for(int i = 0; i < n; i++) {
		if(!done[i]) continue;

		for(int j : con[group[i]]) na[j] = 1;
		
		for(int u : adj[i]) {
			if(done[u]) continue;

			id++;
	

			Vis.clear();
			travel(u, -1);

			assert(Vis.size() < SZ);



			int sz = Vis.size();
			int rem = SZ - sz;


			na_con.clear();
			dfs2(i, -1);

			set<int> bt;
			for(int j = 0; j < SZ; j++) bt.insert(j);

			for(int j = 0; j < rem; j++) {
				bt.erase(bit[na_con[j]]);
				con[id].push_back(na_con[j]);

			}

			for(int j = 0; j < sz; j++) {
				con[id].push_back(Vis[j]);
				bit[Vis[j]] = *bt.begin();
				bt.erase(bt.begin());
				group[Vis[j]] = id;
				done[Vis[j]] = 1;
			}			
		}

		for(int j : con[group[i]]) na[j] = 0;
		
	}


}
void Joi(int N, int M, int A[], int B[], long long X, int T) {
	n = N;
	for(int i = 0; i < M; i++) {
		g[A[i]].push_back(B[i]);
		g[B[i]].push_back(A[i]);
	}

	dfs0(0);

	dfs(0, -1);
	prc();

	// for(int i = 1; i <= id; i++) {
	// 	cout<<"GROUP "<<i<<":   ";
	// 	for(int j : con[i]) cout<<j<<" ";
	// 	cout<<endl;
	// }



	for(int i = 0; i < n; i++) {
		assert(done[i]);
		
		MessageBoard(i, ((X >> bit[i]) & 1));
	}
}
#include "Ioi.h"

#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
using namespace std;
const int mxn=1e5+5;
const int inf=1e9;

struct CON {
	vector<int> g[mxn];
	vector<int> adj[mxn];
	int n;
	int vis[mxn] = {};
	const int SZ = 60;
	void dfs0(int u) {
		vis[u] = 1;
		for(int v : g[u]) {
			if(vis[v]) continue;
			adj[u].push_back(v);
			adj[v].push_back(u);
			dfs0(v);
		}
	}


	int bit[mxn] = {};
	int group[mxn] = {};
	vector<int> con[mxn];

	int id = 0;
	int done[mxn] = {};


	vector<int> dfs(int u, int prev) {

		vector<int> cur;

		cur.push_back(u);
		for(int v : adj[u]) {
			if(v == prev) continue;
			vector<int> x = dfs(v, u);

			for(int i : x) cur.push_back(i);
		}


	    if(cur.size() < SZ) return cur;
	    id++;
	    for(int i = 0; i < SZ; i++) {
	    	group[cur[i]] = id;
	    	bit[cur[i]] = i;
	    	con[id].push_back(cur[i]);
	    	done[cur[i]] = 1;
	    }

	    return {};
	}


	vector<int> Vis;
	void travel(int u, int prev) {
		Vis.push_back(u);
		done[u] = 1;
		for(int v : adj[u]) {
			if(v == prev || done[v]) continue;
			travel(v, u);

		}
	}

	bool na[mxn] = {};

	vector<int> na_con;

	void dfs2(int u, int prev) {
		na_con.push_back(u);
		for(int v : adj[u]) {
			if(v == prev || !na[v]) continue;
			dfs2(v, u);
		}
	} 

	void prc() {
		for(int i = 0; i < n; i++) {
			if(!done[i]) continue;

			for(int j : con[group[i]]) na[j] = 1;
			
			for(int u : adj[i]) {
				if(done[u]) continue;

				id++;
				// cout<<"NEW GROUP FROM start "<<i<<" Index "<<id<<endl;



				Vis.clear();
				travel(u, -1);

				assert(Vis.size() < SZ);



				int sz = Vis.size();
				int rem = SZ - sz;


				na_con.clear();
				dfs2(i, -1);

				set<int> bt;
				for(int j = 0; j < SZ; j++) bt.insert(j);

				for(int j = 0; j < rem; j++) {
					bt.erase(bit[na_con[j]]);
					con[id].push_back(na_con[j]);
				}

				for(int j = 0; j < sz; j++) {
					con[id].push_back(Vis[j]);
					bit[Vis[j]] = *bt.begin();
					bt.erase(bt.begin());
					group[Vis[j]] = id;
					done[Vis[j]] = 1;
				}			
			}

			for(int j : con[group[i]]) na[j] = 0;
			
		}


	}

	ll ans = 0;
	bool allowed[mxn] = {};

	void get_ans(int u, int prev) {

		for(int v : adj[u]) {
			if(v == prev || !allowed[v]) continue;
			ll x = Move(v);
			ans |= (x << bit[v]);
			get_ans(v, u);

		}

		if(prev != -1) Move(prev);
	}	
} cc;

bool allowed[mxn] = {};

long long Ioi(int N, int M, int A[], int B[], int P, int V, int T) {
	cc.n = N;
	for(int i = 0; i < M; i++) {
		cc.g[A[i]].push_back(B[i]);
		cc.g[B[i]].push_back(A[i]);
	}
	cc.dfs0(0);
	cc.dfs(0, -1);
	cc.prc();

	ll v = V;
	cc.ans |= v << (cc.bit[P]);

	for(int i = 0; i < cc.SZ; i++) {
		cc.allowed[cc.con[cc.group[P]][i]] = 1;
		// cout<<cc.con[cc.group[P]][i]<<" ";
	}
	// cout<<endl;

	cc.get_ans(P, -1);



	return cc.ans;



}

Compilation message

Ioi.cpp: In member function 'std::vector<int> CON::dfs(int, int)':
Ioi.cpp:48:20: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'const int' [-Wsign-compare]
   48 |      if(cur.size() < SZ) return cur;
      |         ~~~~~~~~~~~^~~~
In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from Ioi.cpp:3:
Ioi.cpp: In member function 'void CON::prc()':
Ioi.cpp:101:23: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'const int' [-Wsign-compare]
  101 |     assert(Vis.size() < SZ);
      |            ~~~~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 9 ms 16532 KB Output is correct
2 Correct 8 ms 16536 KB Output is correct
3 Correct 9 ms 16504 KB Output is correct
4 Correct 8 ms 16532 KB Output is correct
5 Correct 9 ms 16540 KB Output is correct
6 Correct 9 ms 16400 KB Output is correct
7 Correct 9 ms 16548 KB Output is correct
8 Correct 11 ms 16664 KB Output is correct
9 Correct 9 ms 16672 KB Output is correct
10 Correct 9 ms 16532 KB Output is correct
11 Correct 12 ms 16864 KB Output is correct
12 Correct 8 ms 16516 KB Output is correct
13 Correct 9 ms 16544 KB Output is correct
14 Correct 10 ms 16544 KB Output is correct
15 Correct 9 ms 16532 KB Output is correct
16 Correct 10 ms 16520 KB Output is correct
17 Correct 9 ms 16544 KB Output is correct
18 Correct 10 ms 16544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 22388 KB Output is correct
2 Correct 47 ms 22212 KB Output is correct
3 Correct 46 ms 22252 KB Output is correct
4 Correct 39 ms 19236 KB Output is correct
5 Correct 36 ms 20816 KB Output is correct
6 Correct 36 ms 20240 KB Output is correct
7 Correct 38 ms 20492 KB Output is correct
8 Correct 37 ms 20604 KB Output is correct
9 Correct 37 ms 20544 KB Output is correct
10 Correct 270 ms 23672 KB Output is correct
11 Correct 277 ms 23812 KB Output is correct
12 Correct 31 ms 18932 KB Output is correct
13 Correct 32 ms 18844 KB Output is correct
14 Correct 33 ms 18956 KB Output is correct
15 Correct 45 ms 19400 KB Output is correct
16 Correct 40 ms 19332 KB Output is correct
17 Correct 37 ms 19252 KB Output is correct
18 Correct 40 ms 19216 KB Output is correct
19 Correct 39 ms 19264 KB Output is correct
20 Correct 31 ms 21012 KB Output is correct
21 Correct 32 ms 21024 KB Output is correct
22 Correct 33 ms 20000 KB Output is correct
23 Correct 34 ms 20544 KB Output is correct
24 Correct 35 ms 20052 KB Output is correct
25 Correct 35 ms 20316 KB Output is correct
26 Correct 34 ms 20464 KB Output is correct
27 Correct 33 ms 20472 KB Output is correct
28 Correct 34 ms 20804 KB Output is correct
29 Correct 32 ms 20112 KB Output is correct
30 Correct 32 ms 20244 KB Output is correct
31 Correct 9 ms 16536 KB Output is correct
32 Correct 8 ms 16524 KB Output is correct
33 Correct 11 ms 16656 KB Output is correct
34 Correct 10 ms 16532 KB Output is correct
35 Correct 9 ms 16540 KB Output is correct
36 Correct 9 ms 16524 KB Output is correct
37 Correct 9 ms 16524 KB Output is correct
38 Correct 10 ms 16532 KB Output is correct
39 Correct 10 ms 16532 KB Output is correct
40 Correct 9 ms 16532 KB Output is correct
41 Correct 9 ms 16520 KB Output is correct
42 Correct 8 ms 16540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 16532 KB Output is correct
2 Correct 8 ms 16528 KB Output is correct
3 Correct 11 ms 16488 KB Output is correct
4 Correct 15 ms 17600 KB Output is correct
5 Correct 14 ms 17472 KB Output is correct
6 Correct 13 ms 17592 KB Output is correct
7 Correct 12 ms 17600 KB Output is correct
8 Correct 12 ms 17592 KB Output is correct
9 Correct 34 ms 22912 KB Output is correct
10 Correct 35 ms 22848 KB Output is correct
11 Correct 35 ms 22988 KB Output is correct
12 Correct 10 ms 16512 KB Output is correct
13 Correct 11 ms 16528 KB Output is correct
14 Correct 9 ms 16492 KB Output is correct
15 Correct 8 ms 16524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 47 ms 22292 KB Output is correct
2 Correct 52 ms 22252 KB Output is correct
3 Correct 53 ms 22372 KB Output is correct
4 Correct 40 ms 19296 KB Output is correct
5 Correct 38 ms 21776 KB Output is correct
6 Correct 36 ms 20796 KB Output is correct
7 Correct 37 ms 20468 KB Output is correct
8 Correct 37 ms 19964 KB Output is correct
9 Correct 37 ms 20260 KB Output is correct
10 Correct 292 ms 23692 KB Output is correct
11 Correct 269 ms 23756 KB Output is correct
12 Correct 35 ms 18812 KB Output is correct
13 Correct 33 ms 18784 KB Output is correct
14 Correct 33 ms 18984 KB Output is correct
15 Correct 41 ms 19484 KB Output is correct
16 Correct 40 ms 19484 KB Output is correct
17 Correct 40 ms 19256 KB Output is correct
18 Correct 40 ms 19284 KB Output is correct
19 Correct 46 ms 19316 KB Output is correct
20 Correct 32 ms 21044 KB Output is correct
21 Correct 33 ms 20936 KB Output is correct
22 Correct 34 ms 20448 KB Output is correct
23 Correct 34 ms 20260 KB Output is correct
24 Correct 34 ms 20220 KB Output is correct
25 Correct 34 ms 20548 KB Output is correct
26 Correct 35 ms 20496 KB Output is correct
27 Correct 36 ms 20844 KB Output is correct
28 Correct 35 ms 20072 KB Output is correct
29 Correct 31 ms 19992 KB Output is correct
30 Correct 32 ms 20260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 47 ms 22280 KB Output is correct
2 Correct 48 ms 22328 KB Output is correct
3 Correct 48 ms 22220 KB Output is correct
4 Correct 38 ms 19212 KB Output is correct
5 Correct 36 ms 22296 KB Output is correct
6 Correct 38 ms 20272 KB Output is correct
7 Correct 39 ms 19988 KB Output is correct
8 Correct 39 ms 20512 KB Output is correct
9 Correct 41 ms 20520 KB Output is correct
10 Correct 267 ms 23732 KB Output is correct
11 Correct 319 ms 23812 KB Output is correct
12 Correct 33 ms 18876 KB Output is correct
13 Correct 32 ms 18788 KB Output is correct
14 Correct 32 ms 18936 KB Output is correct
15 Correct 40 ms 19376 KB Output is correct
16 Correct 49 ms 19380 KB Output is correct
17 Correct 40 ms 19228 KB Output is correct
18 Correct 39 ms 19320 KB Output is correct
19 Correct 39 ms 19240 KB Output is correct
20 Correct 31 ms 21036 KB Output is correct
21 Correct 31 ms 21032 KB Output is correct
22 Correct 32 ms 20316 KB Output is correct
23 Correct 33 ms 20212 KB Output is correct
24 Correct 33 ms 20172 KB Output is correct
25 Correct 34 ms 20284 KB Output is correct
26 Correct 39 ms 19952 KB Output is correct
27 Correct 33 ms 20872 KB Output is correct
28 Correct 35 ms 20764 KB Output is correct
29 Correct 34 ms 20568 KB Output is correct
30 Correct 32 ms 20196 KB Output is correct
31 Correct 9 ms 16524 KB Output is correct
32 Correct 8 ms 16516 KB Output is correct
33 Correct 11 ms 16648 KB Output is correct
34 Correct 8 ms 16532 KB Output is correct
35 Correct 8 ms 16512 KB Output is correct
36 Correct 8 ms 16540 KB Output is correct
37 Correct 9 ms 16540 KB Output is correct
38 Correct 8 ms 16496 KB Output is correct
39 Correct 8 ms 16540 KB Output is correct
40 Correct 9 ms 16592 KB Output is correct
41 Correct 8 ms 16540 KB Output is correct
42 Correct 9 ms 16532 KB Output is correct