103402024-03-31 20:46:14111Úthálózatbővítéscpp17Time limit exceeded 10/100600ms64556 KiB
#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
using namespace std;

#define int long long

#define INF (int)1e8

struct P{
	int x,y;
};

struct L{
	P l,h;
};

bool operator==(P a,P b){
	return a.x==b.x&&a.y==b.y;
}

bool operator<(P a,P b){
	return a.x<b.x||a.x==b.x&&a.y<b.y;
}

P operator+(P a,P b){
	return P{a.x+b.x,a.y+b.y};
}

P operator-(P a,P b){
	return P{a.x-b.x,a.y-b.y};
}

istream&operator>>(istream&is,P&p){
	return is>>p.x>>p.y;
}

ostream&operator<<(ostream&os,P p){
	return os<<'('<<p.x<<','<<p.y<<')';
}

int sign(int x){
	return (x>0)-(x<0);
}

int cross(P a,P b){
	return a.x*b.y-b.x*a.y;
}

int orient(P a,P b,P c){
	return sign(cross(a-b,c-b));
}

int right(P a,P b,P c){
	return cross(a-b,c-b)>=0;
}

int test(L a,L b){
	if(a.l==b.l||a.l==b.h||a.h==b.l||a.h==b.h){
		return false;
	}
	int o1=orient(a.l,a.h,b.l);
	int o2=orient(a.l,a.h,b.h);
	int o3=orient(b.l,b.h,a.l);
	int o4=orient(b.l,b.h,a.h);
	return o1!=o2&&o3!=o4;
}

bool operator<(L a,L b){
	if(a.l==b.h){
		return false;
	}
	if(a.h==b.l){
		return true;
	}
	int x=!right(b.h,b.l,a.l);
	int y=!right(a.h,a.l,b.l);
	if(x==y){
		x=!right(b.h,b.l,a.h);
		y=!right(a.h,a.l,b.h);
	}
	return x>y;
}

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int N;
	cin>>N;
	vector<pair<P,int>>v(N+1);
	for(int i=0;i<=N;i++){
		cin>>v[i].first;
		v[i].second=i;
	}
	vector<L>e;
	for(int i=1;i<=N;i++){
		e.push_back(L{v[0].first,v[i].first});
	}
	for(int i=0;i<N-1;i++){
		int a,b;
		cin>>a>>b;
		e.push_back(L{v[a].first,v[b].first});
	}
	for(auto&p:e){
		if(p.h<p.l){
			swap(p.l,p.h);
		}
	}
	vector<int>ans(N,1);
	vector<tuple<P,int,int>>q;
	for(int i=0;i<e.size();i++){
		q.emplace_back(e[i].l,1,i);
		q.emplace_back(e[i].h,2,i);
	}
	sort(q.begin(),q.end());
	set<pair<L,int>>s;
	s.emplace(L{P{-INF,-INF},P{INF,-INF}},-1);
	s.emplace(L{P{-INF,INF},P{INF,INF}},-1);
	for(auto[p,o,i]:q){
		if(o==1){
			auto it=s.insert(pair<L,int>(e[i],i)).first;
			auto lt=prev(it);
			auto rt=next(it);
			while(test(it->first,lt->first)){
				if(it->second<N){
					ans[it->second]=0;
					it=s.erase(it);
				}
				else{
					if(lt->second>=N){
						exit(1);
					}
					ans[lt->second]=0;
					lt=prev(s.erase(lt));
				}
			}
			while(test(it->first,rt->first)){
				if(it->second<N){
					ans[it->second]=0;
					it=prev(s.erase(it));
				}
				else{
					if(rt->second>=N){
						exit(1);
					}
					ans[rt->second]=0;
					rt=s.erase(rt);
				}
			}
		}
		if(o==2){
			auto it=s.find(pair<L,int>(e[i],i));
			if(it!=s.end()){
				it=s.erase(it);
				auto lt=prev(it);
				while(test(it->first,lt->first)){
					if(it->second<N){
						ans[it->second]=0;
						it=s.erase(it);
					}
					else{
						if(lt->second>=N){
							exit(1);
						}
						ans[lt->second]=0;
						lt=prev(s.erase(lt));
					}
				}
			}
		}
	}
	cout<<count(ans.begin(),ans.end(),1)<<'\n';
	for(int i=0;i<N;i++){
		if(ans[i]){
			cout<<i+1<<' ';
		}
	}
	cout<<'\n';
	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms2096 KiB
2Time limit exceeded600ms26212 KiB
subtask210/10
3Accepted3ms4464 KiB
4Accepted3ms4672 KiB
5Accepted4ms4920 KiB
6Accepted8ms5216 KiB
7Accepted12ms5464 KiB
subtask30/20
8Accepted3ms4928 KiB
9Accepted4ms4972 KiB
10Accepted16ms5840 KiB
11Accepted79ms8164 KiB
12Accepted171ms11544 KiB
13Time limit exceeded564ms18944 KiB
14Time limit exceeded515ms33560 KiB
15Wrong answer451ms21052 KiB
16Time limit exceeded542ms27188 KiB
17Time limit exceeded536ms22528 KiB
subtask40/10
18Accepted4ms10828 KiB
19Accepted61ms12948 KiB
20Wrong answer211ms16952 KiB
21Accepted163ms17124 KiB
22Accepted108ms14692 KiB
subtask50/30
23Accepted20ms12368 KiB
24Accepted166ms17552 KiB
25Accepted8ms11752 KiB
26Accepted9ms11952 KiB
27Accepted108ms14940 KiB
28Accepted238ms19116 KiB
29Accepted340ms24712 KiB
30Time limit exceeded547ms19272 KiB
31Time limit exceeded542ms31576 KiB
32Time limit exceeded574ms27236 KiB
subtask60/30
33Time limit exceeded574ms28128 KiB
34Time limit exceeded582ms29352 KiB
35Time limit exceeded563ms33492 KiB
36Time limit exceeded569ms33440 KiB
37Time limit exceeded564ms33436 KiB
38Runtime error137ms64556 KiB
39Runtime error144ms64508 KiB
40Runtime error158ms64508 KiB
41Runtime error138ms64480 KiB
42Time limit exceeded564ms29392 KiB