#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
/*
refs:
some hidden tcs (to identify the bug)
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 += 3, a[i].ss += 3;
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[siz+5][siz+5];
memset(dis,0x3f,sizeof dis);
memset(vis,0,sizeof vis);
deque<pii> dq;
dq.pb({0,0});
dis[0][0] = 0;
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 = true;
for(int y = y1; y < y2; ++y){
if(dis[x1-1][y] != dis[x1][y]){
ok = false;
}
}
if(ok){
ans.pb(i);
}
for(int y = y1; y < y2; ++y){
assert(dis[x1-1][y] == dis[x1-1][y1]);
}
}
// same row
else if(y1 == y2){
if(x1 > x2) swap(x1,x2);
bool ok = true;
for(int x = x1; x < x2; ++x){
if(dis[x][y1-1] != dis[x][y1]){
ok = false;
}
}
if(ok){
ans.pb(i);
}
for(int x = x1; x < x2; ++x){
assert(dis[x][y1-1] == dis[x1][y1-1]);
}
}
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 |
Correct |
12 ms |
1628 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
1628 KB |
Output is correct |
2 |
Correct |
10 ms |
1628 KB |
Output is correct |
3 |
Correct |
9 ms |
1728 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
31 ms |
3164 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
3420 KB |
Output is correct |
2 |
Correct |
26 ms |
3416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
3676 KB |
Output is correct |
2 |
Correct |
2 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
142 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
146 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
145 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
146 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
136 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
198 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
168 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
146 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
146 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |