Submission #979813

# Submission time Handle Problem Language Result Execution time Memory
979813 2024-05-11T12:07:26 Z parlimoos Meetings (JOI19_meetings) C++14
100 / 100
489 ms 4944 KB
//Be Name KHODA
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include "meetings.h"
using namespace std;

typedef long long ll;
typedef long double ld;
#define pb push_back
#define pp pop_back
#define lb lower_bound
#define ub upper_bound
#define cl clear
#define bg begin
#define arr(x) array<int , x>
#define endl '\n'

int n , sz;
set<int> g[2000];
int cs[2000];
bool blk[2000][2000] , ms[2000];
vector<arr(2)> blks;
int cnt = 0;

//int Query(int v , int u , int w){
//	cout << "Q : {" << v << " , " << u << " , " << w << "}\n";
//	int res;
//	cin >> res;
//	return res;
//}
//void Bridge(int v , int u){
//	cout << "There is an edge between " << v << " and " << u << ".\n";
//	string res;
//	cin >> res;
//	if(res == "no") exit(0);
//}
void dfs1(int v , int p){
	cs[v] = 1;
	for(int u : g[v]){
		if(blk[v][u] or u == p) continue;
		dfs1(u , v) , cs[v] += cs[u];
	}
}
int getCnt(int v , int p){
	for(int u : g[v]){
		if(blk[v][u] or u == p) continue;
		if(cs[u] > sz / 2) return getCnt(u , v);
	}
	return v;
}
void connect(int v , int u){
	g[v].insert(u) , g[u].insert(v);
}
void addIn(int v , int w , int u){
	g[v].erase(w) , g[w].erase(v);
	connect(v , u) , connect(w , u);
}
void setBlk(int v , int u , bool vl){
	blk[v][u] = vl , blk[u][v] = vl;
	if(vl) blks.pb({v , u});
}
void Solve(int N){
	n = N , cnt = 3;
	int x = Query(0 , 1 , 2);
	if(x >= 0 and x <= 2){
		int v = 0 , u = 1;
		if(3 - x == 2) u = 2;
		if(3 - x == 3) v = 2;
		connect(x , v) , connect(x , u);
	}else{
		ms[x] = 1 , cnt++;
		for(int v = 0 ; v < 3 ; v++) connect(x , v);
	}
	
	for(int v = 3 ; v < n ; v++){
		if(!g[v].empty()) continue;
		int r = 0;
		sz = cnt;
		while(sz > 1){
			dfs1(r , -1);
//			if(sz == 5){
//				for(int i = 0 ; i < n ; i++){
//					if(g[i].empty()) continue;
//					cout << i << " " << cs[i] << " : ";
//					for(int u : g[i]) cout << u << " , ";
//					cout << "||\n" << flush;
//				}
//			}
			int c = getCnt(r , -1);
//			cout << "Centroid is " << c << ".\n";
			vector<arr(2)> ord;
			for(int u : g[c]){
				if(blk[c][u]) continue;
				if(cs[u] > cs[c]) ord.pb({sz - cs[c] , u});
				else ord.pb({cs[u] , u});
			}
			sort(ord.bg() , ord.end() , [](arr(2) a , arr(2) b){
				return (a[0] > b[0]);
			});
			
			for(int i = 0 ; i < (int)ord.size() ; i += 2){
				if(i == (int)ord.size() - 1){
					int x = Query(ord[i][1] , c , v);
					if(x == ord[i][1]){
						sz = ord[i][0] , r = ord[i][1] , setBlk(c , ord[i][1] , 1);
						break;
					}else{
						sz = 0 , r = -1;
						if(x == c) r = c;
						else if(x == v) addIn(c , ord[i][1] , v);
						else{
							ms[x] = 1 , cnt++ , addIn(c , ord[i][1] , x) , connect(x , v);
						}
					}
				}else{
					auto u = ord[i] , w = ord[i + 1];
					int x = Query(v , u[1] , w[1]);
					sz = 0 , r = -1;
					if(x == u[1] or x == w[1]){
						sz = u[0] , r = x , setBlk(c , x , 1);
						if(x == w[1]) sz = w[0];
//						cout << w[0] << " " << w[1] << "$$\n";
						break;
					}else if(x == c){
						if(i < (int)ord.size() - 2) continue;
						r = c;
					}else if(x == v){
						if(Query(c , v , u[1]) == v) addIn(c , u[1] , v);
						else addIn(c , w[1] , v);
						break;
					}else{
						ms[x] = 1 , cnt++;
						if(Query(c , x , u[1]) == x){
							addIn(c , u[1] , x) , connect(x , v);
						}else{
							addIn(c , w[1] , x) , connect(x , v);
						}
						break;
					}
				}
			}
//			cout << "L\n" << flush;
		}
		if(r != -1) connect(r , v);
		for(auto b : blks) setBlk(b[0] , b[1] , 0);
		blks.cl() , cnt++;
//		cout << "_____\n" << flush;
	}
	
	for(int v = 0 ; v < n ; v++){
		for(int u : g[v]){
			if(u > v) continue;
			Bridge(u , v);
		}
	}
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 600 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 600 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
15 Correct 1 ms 600 KB Output is correct
16 Correct 1 ms 600 KB Output is correct
17 Correct 1 ms 600 KB Output is correct
18 Correct 1 ms 600 KB Output is correct
19 Correct 1 ms 600 KB Output is correct
20 Correct 1 ms 600 KB Output is correct
21 Correct 0 ms 600 KB Output is correct
22 Correct 1 ms 600 KB Output is correct
23 Correct 1 ms 600 KB Output is correct
24 Correct 1 ms 600 KB Output is correct
25 Correct 1 ms 600 KB Output is correct
26 Correct 1 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 600 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
15 Correct 1 ms 600 KB Output is correct
16 Correct 1 ms 600 KB Output is correct
17 Correct 1 ms 600 KB Output is correct
18 Correct 1 ms 600 KB Output is correct
19 Correct 1 ms 600 KB Output is correct
20 Correct 1 ms 600 KB Output is correct
21 Correct 0 ms 600 KB Output is correct
22 Correct 1 ms 600 KB Output is correct
23 Correct 1 ms 600 KB Output is correct
24 Correct 1 ms 600 KB Output is correct
25 Correct 1 ms 600 KB Output is correct
26 Correct 1 ms 600 KB Output is correct
27 Correct 4 ms 856 KB Output is correct
28 Correct 4 ms 856 KB Output is correct
29 Correct 4 ms 856 KB Output is correct
30 Correct 4 ms 856 KB Output is correct
31 Correct 3 ms 856 KB Output is correct
32 Correct 4 ms 600 KB Output is correct
33 Correct 5 ms 600 KB Output is correct
34 Correct 6 ms 600 KB Output is correct
35 Correct 6 ms 600 KB Output is correct
36 Correct 4 ms 856 KB Output is correct
37 Correct 7 ms 1112 KB Output is correct
38 Correct 8 ms 1072 KB Output is correct
39 Correct 6 ms 1112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 208 ms 3304 KB Output is correct
2 Correct 223 ms 3316 KB Output is correct
3 Correct 214 ms 3672 KB Output is correct
4 Correct 195 ms 3412 KB Output is correct
5 Correct 218 ms 3828 KB Output is correct
6 Correct 184 ms 3124 KB Output is correct
7 Correct 256 ms 1616 KB Output is correct
8 Correct 287 ms 1452 KB Output is correct
9 Correct 292 ms 1344 KB Output is correct
10 Correct 272 ms 1360 KB Output is correct
11 Correct 313 ms 1672 KB Output is correct
12 Correct 271 ms 4004 KB Output is correct
13 Correct 231 ms 3284 KB Output is correct
14 Correct 254 ms 1436 KB Output is correct
15 Correct 250 ms 1528 KB Output is correct
16 Correct 254 ms 1576 KB Output is correct
17 Correct 254 ms 1104 KB Output is correct
18 Correct 223 ms 1368 KB Output is correct
19 Correct 231 ms 1484 KB Output is correct
20 Correct 264 ms 1796 KB Output is correct
21 Correct 272 ms 2128 KB Output is correct
22 Correct 257 ms 1872 KB Output is correct
23 Correct 254 ms 1872 KB Output is correct
24 Correct 298 ms 1924 KB Output is correct
25 Correct 237 ms 2312 KB Output is correct
26 Correct 240 ms 2132 KB Output is correct
27 Correct 246 ms 2132 KB Output is correct
28 Correct 355 ms 1524 KB Output is correct
29 Correct 284 ms 1480 KB Output is correct
30 Correct 282 ms 1360 KB Output is correct
31 Correct 302 ms 1372 KB Output is correct
32 Correct 489 ms 4872 KB Output is correct
33 Correct 337 ms 4944 KB Output is correct
34 Correct 6 ms 856 KB Output is correct
35 Correct 4 ms 856 KB Output is correct
36 Correct 4 ms 856 KB Output is correct
37 Correct 3 ms 856 KB Output is correct
38 Correct 4 ms 856 KB Output is correct
39 Correct 4 ms 648 KB Output is correct
40 Correct 5 ms 600 KB Output is correct
41 Correct 6 ms 600 KB Output is correct
42 Correct 6 ms 600 KB Output is correct
43 Correct 4 ms 856 KB Output is correct
44 Correct 6 ms 1112 KB Output is correct
45 Correct 8 ms 1048 KB Output is correct
46 Correct 6 ms 1108 KB Output is correct
47 Correct 1 ms 600 KB Output is correct
48 Correct 0 ms 600 KB Output is correct
49 Correct 1 ms 600 KB Output is correct
50 Correct 1 ms 600 KB Output is correct
51 Correct 1 ms 600 KB Output is correct
52 Correct 1 ms 600 KB Output is correct
53 Correct 0 ms 600 KB Output is correct
54 Correct 0 ms 600 KB Output is correct
55 Correct 0 ms 600 KB Output is correct
56 Correct 1 ms 600 KB Output is correct
57 Correct 1 ms 600 KB Output is correct
58 Correct 1 ms 600 KB Output is correct
59 Correct 1 ms 600 KB Output is correct
60 Correct 0 ms 344 KB Output is correct
61 Correct 0 ms 344 KB Output is correct
62 Correct 0 ms 344 KB Output is correct
63 Correct 0 ms 344 KB Output is correct
64 Correct 0 ms 344 KB Output is correct
65 Correct 0 ms 344 KB Output is correct
66 Correct 1 ms 344 KB Output is correct
67 Correct 0 ms 344 KB Output is correct
68 Correct 0 ms 344 KB Output is correct
69 Correct 0 ms 344 KB Output is correct
70 Correct 0 ms 344 KB Output is correct
71 Correct 1 ms 344 KB Output is correct
72 Correct 0 ms 600 KB Output is correct