제출 #513828

#제출 시각아이디문제언어결과실행 시간메모리
513828fatemetmhrMeetings (JOI19_meetings)C++17
29 / 100
1951 ms12556 KiB
//  ~Be name khoda~  //

#include "meetings.h"
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

#define pb       push_back
#define mp       make_pair
#define all(x)   x.begin(), x.end()
#define fi       first
#define se       second
#define cl       clear
#define endll    '\n'

const int maxn  =  1e6   + 10;
const int maxn5 =  5e5   + 10;
const int maxnt =  1.2e6 + 10;
const int maxn3 =  1e3   + 10;
const int mod   =  1e9   +  7;
const ll  inf   =  2e18;

int n;
vector <int> adj[maxn5], tmp, av;
int mx[maxn5], sz[maxn5];
bool rem[maxn5], mark[maxn5];

inline void remo(int a, int b){
	tmp.clear();
	for(auto u : adj[a]) 
		if(u != b) tmp.pb(u);
	adj[a].clear();
	for(auto u : tmp)
		adj[a].pb(u);
	return;
}

inline void dfs(int v, int par){
	sz[v] = 1;
	mx[v] = 0;
	av.pb(v);
	for(auto u : adj[v]) if(u != par && !rem[u]){
		dfs(u, v);
		mx[v] = max(mx[v], sz[u]);
		sz[v] += sz[u];
	}
	return;
}


inline void add(int r, int v){
	//cout << "adding " << r << ' ' << v << endl;
	av.clear();
	dfs(r, -1);
	int c = r;
	for(auto u : av)
		if(max(mx[u], int(av.size()) - sz[u]) < max(mx[c], int(av.size()) - sz[c]))
			c = u;
	int sub = -1;
	//cout << "centroid " << c << endl;
	assert(adj[c].size() <= 18);
	for(auto uu : adj[c]) if(!rem[uu]){
		int u = uu;
		int t = Query(c, u, v);
		if(t == v){
			//cout << "right " << u << endl;
			remo(u, c);
			remo(c, u);
			adj[u].pb(v);
			adj[c].pb(v);
			adj[v].pb(u);
			adj[v].pb(c);
			return;
		}
		else if(t == u){
			sub = u;
			break;
		}
		else if(t != c){
			remo(u, c);
			remo(c, u);
			adj[u].pb(t);
			adj[v].pb(t);
			adj[c].pb(t);
			adj[t].pb(u);
			adj[t].pb(c);
			adj[t].pb(v);
			mark[t] = true;
			return;
		}
	}
	//cout << "ok " << sub << endl;
	if(sub != -1){
		rem[c] = true;
		add(sub, v);
		return;
	}
	adj[c].pb(v);
	adj[v].pb(c);
}

void Solve(int nn){
	n = nn;
	for(int i = 1; i < n; i++) if(!mark[i]){
		fill(rem, rem + n + 5, false);
		add(0, i);
		mark[i] = true;
	}
	for(int i = 0; i < n; i++) for(auto u : adj[i]){
		//cout << "edge " << i << ' '<< u << endl;
		if(i < u) Bridge(i, u);
	}
	return;
}

/*
5
0 4
2 4
2 3
1 4
*/











#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...