#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define pb push_back
#define endl '\n'
#define sz(a) (int)a.size()
#define setbits(x) __builtin_popcountll(x)
#define ff first
#define ss second
#define conts continue
#define ceil2(x,y) ((x+y-1)/(y))
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
#define rev(i,s,e) for(int i = s; i >= e; --i)
#define trav(i,a) for(auto &i : a)
template<typename T>
void amin(T &a, T b) {
a = min(a,b);
}
template<typename T>
void amax(T &a, T b) {
a = max(a,b);
}
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
/*
read the edi a long time ago, remember some key ideas from there
*/
const int MOD = 1e9 + 7;
const int N = 1e5 + 5;
const int inf1 = int(1e9) + 5;
const ll inf2 = ll(1e18) + 5;
vector<int> dx = {-1,1,0,0};
vector<int> dy = {0,0,-1,1};
void solve(int test_case)
{
ll n; cin >> n;
vector<pll> a(n+5);
rep1(i,n) cin >> a[i].ff >> a[i].ss;
rep1(i,n) a[i].ff++, a[i].ss++;
ll m; cin >> m;
vector<pll> b(m+5);
rep1(i,m) cin >> b[i].ff >> b[i].ss;
set<array<ll,4>> st;
rep1(i,m){
auto [x1,y1] = a[b[i].ff];
auto [x2,y2] = a[b[i].ss];
// same col
if(x1 == x2){
if(y1 > y2) swap(y1,y2);
for(int y = y1; y < y2; ++y){
st.insert({x1-1,y,x1,y});
st.insert({x1,y,x1-1,y});
}
}
// same row
else if(y1 == y2){
if(x1 > x2) swap(x1,x2);
for(int x = x1; x < x2; ++x){
st.insert({x,y1-1,x,y1});
st.insert({x,y1,x,y1-1});
}
}
else{
assert(0);
}
}
ll siz = 0;
rep1(i,n) amax(siz,a[i].ff), amax(siz,a[i].ss);
ll dis[siz+5][siz+5];
bool vis[n+5][n+5];
memset(dis,0x3f,sizeof dis);
memset(vis,0,sizeof vis);
vector<pll> src = {
{0,0},
{0,siz+3},
{siz+3,0},
{siz+3,siz+3}
};
deque<pii> dq;
for(auto [i,j] : src){
dis[i][j] = 0;
dq.pb({i,j});
}
while(!dq.empty()){
auto [i,j] = dq.front();
dq.pop_front();
if(vis[i][j]) conts;
vis[i][j] = 1;
rep(d,4){
int i2 = i+dx[d], j2 = j+dy[d];
if(i2 < 0 or i2 >= siz+5 or j2 < 0 or j2 >= siz+5) conts;
if(st.count({i,j,i2,j2})){
if(dis[i][j]+1 < dis[i2][j2]){
dq.pb({i2,j2});
dis[i2][j2] = dis[i][j]+1;
}
}
else{
if(dis[i][j] < dis[i2][j2]){
dq.push_front({i2,j2});
dis[i2][j2] = dis[i][j];
}
}
}
}
vector<ll> ans;
rep1(i,m){
auto [x1,y1] = a[b[i].ff];
auto [x2,y2] = a[b[i].ss];
// same col
if(x1 == x2){
if(y1 > y2) swap(y1,y2);
bool ok = false;
for(int y = y1; y < y2; ++y){
if(dis[x1-1][y] != dis[x1][y]){
ok = true;
}
}
if(!ok){
ans.pb(i);
}
}
// same row
else if(y1 == y2){
if(x1 > x2) swap(x1,x2);
bool ok = false;
for(int x = x1; x < x2; ++x){
if(dis[x1][y1-1] != dis[x1][y1]){
ok = true;
}
}
if(!ok){
ans.pb(i);
}
}
else{
assert(0);
}
}
cout << sz(ans) << endl;
trav(x,ans) cout << x << endl;
}
int main()
{
fastio;
int t = 1;
// cin >> t;
rep1(i, t) {
solve(i);
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
1112 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
1116 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
2652 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
2904 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
2904 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
138 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
162 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
148 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
144 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
140 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
206 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
158 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
139 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
149 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |