이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define jizz ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define pb push_back
#define ET cout << "\n"
#define MEM(i,j) memset(i,j,sizeof i)
#define F first
#define S second
#define MP make_pair
#define ALL(v) v.begin(),v.end()
#define DB(a,s,e) {for(int i=s;i<e;++i) cout << a[i] << " ";ET;}
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
struct mode
{
int x,y,up=-1,dwn=-1,lft=-1,rit=-1;
bool operator<(const mode &a)const{
if(x==a.x) return y<a.y;
return x<a.x;
}
}dots[100105];
int boss[400105];
vector<int> G[400105],ans;
queue<int> q;
int dis[400105];
map<int,int> mp;
bool yee(mode a,mode b)
{
if(a.y==b.y) return a.x>b.x;
return a.y>b.y;
}
int finds(int x)
{
if(x==boss[x]) return x;
return boss[x]=finds(boss[x]);
}
void Union(int x,int y)
{
x=finds(x),y=finds(y);
boss[x]=y;
}
int main()
{jizz
int n,w,a,b;
cin >> n;
for(int i=1;i<=n;++i)
cin >> dots[i].x >> dots[i].y;
cin >> w;
for(int i=1;i<=w;++i)
{
cin >> a >> b;
if(dots[b]<dots[a]) swap(a,b);
if(dots[a].x==dots[b].x)
dots[b].dwn=i,dots[a].up=i;
else
dots[a].rit=i,dots[b].lft=i;
}
for(int i=0;i<=2*w+50;++i) boss[i]=i;
sort(dots+1,dots+n+1);
for(int i=1,j=1;i<=n;)
{
for(;j<=n&&dots[i].x==dots[j].x;++j)
if(~dots[j].dwn)
{
auto p=mp.lower_bound(dots[j].y);
if(p!=mp.end()) Union(dots[j].dwn*2,p->S*2+1);
else Union(dots[j].dwn*2,0);
if(p!=mp.begin()) --p,Union(dots[j].dwn*2,p->S*2);
else Union(dots[j].dwn*2,0);
}
for(int k=i;k<j;++k)
{
mp.erase(dots[k].y);
if(~dots[k].rit) mp[dots[k].y]=dots[k].rit;
}
for(;i<j;++i)
if(~dots[i].dwn)
{
auto p=mp.lower_bound(dots[i].y);
if(p!=mp.end()) Union(dots[i].dwn*2+1,p->S*2+1);
else Union(dots[i].dwn*2+1,0);
if(p!=mp.begin()) --p,Union(dots[i].dwn*2+1,p->S*2);
else Union(dots[i].dwn*2+1,0);
}
}
mp.clear();
sort(dots+1,dots+n+1,yee);
for(int i=1,j=1;i<=n;)
{
for(;j<=n&&dots[i].y==dots[j].y;++j)
if(~dots[j].rit)
{
auto p=mp.upper_bound(dots[j].x);
if(p!=mp.end()) Union(dots[j].rit*2,p->S*2);
else Union(dots[j].rit*2,0);
if(p!=mp.begin()) --p,Union(dots[j].rit*2,p->S*2+1);
else Union(dots[j].rit*2,0);
}
else if(!~dots[j].dwn&&~dots[j].up)
{
}
for(int k=i;k<j;++k)
{
mp.erase(dots[k].x);
if(~dots[k].dwn) mp[dots[k].x]=dots[k].dwn;
}
for(;i<j;++i)
if(~dots[i].rit)
{
auto p=mp.upper_bound(dots[i].x);
if(p!=mp.end()) Union(dots[i].rit*2+1,p->S*2);
else Union(dots[i].rit*2+1,0);
if(p!=mp.begin()) --p,Union(dots[i].rit*2+1,p->S*2+1);
else Union(dots[i].rit*2+1,0);
}
}
mp.clear();
for(int i=1;i<=n;++i)
{
if(~dots[i].dwn&&finds(dots[i].dwn*2)!=finds(dots[i].dwn*2+1))
G[boss[dots[i].dwn*2]].pb(boss[dots[i].dwn*2+1]),G[boss[dots[i].dwn*2+1]].pb(boss[dots[i].dwn*2]);
if(~dots[i].rit&&finds(dots[i].rit*2)!=finds(dots[i].rit*2+1))
G[boss[dots[i].rit*2]].pb(boss[dots[i].rit*2+1]),G[boss[dots[i].rit*2+1]].pb(boss[dots[i].rit*2]);
}
dis[finds(0)]=1,q.push(boss[0]);
while(!q.empty())
{
auto u=q.front();
q.pop();
for(int i:G[u])
if(!dis[i])
dis[i]=dis[u]+1,q.push(i);
}
for(int i=1;i<=n;++i)
{
if(~dots[i].dwn&&(dis[boss[dots[i].dwn*2]]==dis[boss[dots[i].dwn*2+1]]||!dis[boss[dots[i].dwn*2]]||!dis[boss[dots[i].dwn*2+1]]))
ans.pb(dots[i].dwn);
if(~dots[i].rit&&(dis[boss[dots[i].rit*2]]==dis[boss[dots[i].rit*2+1]]||!dis[boss[dots[i].rit*2]]||!dis[boss[dots[i].rit*2+1]]))
ans.pb(dots[i].rit);
}
cout << ans.size() << "\n";
for(int i:ans)
cout << i << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |