Submission #900027

# Submission time Handle Problem Language Result Execution time Memory
900027 2024-01-07T12:35:28 Z YassirSalama ICC (CEOI16_icc) C++17
18 / 100
215 ms 756 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <iomanip>
#include <cmath>
#include <limits>
#include <map>
#include <utility>
#include <cctype>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include<assert.h>
#include <functional>
#include <iterator>
#include "icc.h"
using namespace std;
#define OVL(x,s) for(auto y:x) cout<<y<<s; cout<<"\n";
#ifdef IOI
void dbg_out() { cout << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cout << ' ' << H; dbg_out(T...); }
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__);
#else
#define dbg(...) 1337;
#endif
#define endl "\n"
#define pb push_back
#define F first
#define S second
#define ll long long
#define mod 1000000007
#define all(v) v.begin(),v.end()
int ask(vector<int> a,vector<int> b){
	int n=a.size();
	int m=b.size();
	int A[n];
	int B[m];
	for(int i=0;i<n;i++) A[i]=a[i];
	for(int i=0;i<m;i++) B[i]=b[i];
	return query(n,m,A,B);
}
const int MAXN=2e3+100;
int par[MAXN];
vector<vector<int>> v(MAXN);
struct DSU {
	DSU(){
		for(int i=0;i<MAXN;i++) {
			par[i]=i;
			v[i].pb(i);
		}
	}
	int find(int node){
		return node==par[node]?node:par[node]=find(par[node]);
	}
	bool same(int a,int b){
		return find(a)==find(b);
	}
	void merge(int a,int b){
		a=find(a);
		b=find(b);
		if(a==b) return;
		if(v[a].size()<v[b].size()) swap(a,b);
		for(auto x:v[b]) v[a].pb(x);
		v[b].clear();
		par[b]=a;
	}
};
int n;
DSU dsu=DSU();
int dnc(vector<int> a,vector<int> b,int n,int m){
	if(n==1) return a[0];
	int mid=(n)/2;
	vector<int> c,d;
	for(int i=0;i<mid;i++) c.pb(a[i]);
	for(int i=mid;i<n;i++) d.pb(a[i]);
	if(c.size()&&ask(c,b)) return dnc(c,b,c.size(),m);
    if(d.size()&&ask(d,b)) return dnc(d,b,d.size(),m);
    return 0;
}
int dnc2(vector<int> a,vector<int> b,int n,int m){
	if(m==1) return b[0];
	int mid=m/2;
	vector<int> c,d;
	for(int i=0;i<mid;i++) c.pb(b[i]);
	for(int i=mid;i<m;i++) d.pb(b[i]);
	if(c.size()&&ask(a,c)) return dnc2(a,c,n,c.size());
	if(d.size()&&ask(a,d)) return dnc2(a,d,n,d.size());
	return 0;
}
void solve(){
	set<int> a;
	for(int i=1;i<=n;i++){
		a.insert(dsu.find(i));
	}
	vector<int> aa;
	for(auto x:a) aa.pb(x);
	int m=a.size();
    for(int i=0;i<m;i++){
    	vector<int> a;
    	vector<int> b;
    	for(auto x:v[aa[i]]) a.pb(x);
    	for(int j=i+1;j<m;j++){
    		for(auto x:v[aa[j]]) b.pb(x);
    	}
    	if(ask(a,b)){
    		int x=dnc(a,b,a.size(),b.size());
    		// dbg(x);
    		// exit(0);
    		vector<int> c;
    		c.pb(x);
    		int y=dnc2(c,b,1,b.size());
    		// dbg(x,y);
    		// exit(0);
    		setRoad(x,y);
    		dsu.merge(x,y);
    		return;
    	}
    }
}
void run(int N){
	n=N;
	for(int wwww=0;wwww<n-1;wwww++){
		solve();
	}
}

#ifdef IOI
int main(){
	int n;
	cin>>n;
	vector<pair<int,int>> v;
	for(int i=0;i<n-1;i++){
		int a,b;
		cin>>a>>b;
		v.pb({a,b});
	}
	for(int i=0;i<MMS;i++) pr[i]=i;
	EDGES=v;
	mp[{EDGES[0].F,EDGES[0].S}]=1;
	mp[{EDGES[0].S,EDGES[0].F}]=1;

	merge(EDGES[0].F,EDGES[0].S);
 	run(n);
 	cout<<"YES"<<endl;
}
#endif 
# Verdict Execution time Memory Grader output
1 Correct 6 ms 604 KB Ok! 170 queries used.
2 Correct 6 ms 604 KB Ok! 163 queries used.
# Verdict Execution time Memory Grader output
1 Correct 67 ms 752 KB Ok! 1506 queries used.
2 Correct 71 ms 736 KB Ok! 1628 queries used.
3 Correct 69 ms 736 KB Ok! 1675 queries used.
# Verdict Execution time Memory Grader output
1 Incorrect 215 ms 744 KB Number of queries more than 4500 out of 2250
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 193 ms 756 KB Number of queries more than 4000 out of 2000
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 190 ms 740 KB Number of queries more than 3550 out of 1775
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 169 ms 744 KB Number of queries more than 3250 out of 1625
2 Halted 0 ms 0 KB -