#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false);; cin.tie(NULL)
void selfMax(long long& a, long long b){
a = max(a, b);
}
void selfMin(long long& a, long long b){
a = min(a, b);
}
template<typename T> istream& operator>>(istream& in, vector<T>& a) {for(auto &x : a) in >> x; return in;};
template<typename T1, typename T2> istream& operator>>(istream& in, pair<T1, T2>& x) {return in >> x.first >> x.second;}
template<typename T1, typename T2> ostream& operator<<(ostream& out, const pair<T1, T2>& x) {return out << x.first << ' ' << x.second;}
template<typename T> ostream& operator<<(ostream& out, vector<T>& a) {for(auto &x : a) out << x << ' '; return out;};
template<typename T> ostream& operator<<(ostream& out, vector<vector<T> >& a) {for(auto &x : a) out << x << '\n'; return out;};
template<typename T1, typename T2> ostream& operator<<(ostream& out, vector<pair<T1, T2> >& a) {for(auto &x : a) out << x << '\n'; return out;};
/*
Use DSU dsu(n);
*/
struct DSU {
vector<long long> e;
DSU(long long n) { e = vector<long long>(n, -1); }
// get representive component (uses path compression)
long long get(long long x) { return e[x] < 0 ? x : e[x] = get(e[x]); }
bool same_set(long long a, long long b) { return get(a) == get(b); }
long long size(long long x) { return -e[get(x)]; }
bool unite(long long x, long long y) { // union by size
x = get(x), y = get(y);
if (x == y) return false;
if (e[x] > e[y]) swap(x, y);
e[x] += e[y]; e[y] = x;
return true;
}
};
/*
Run with Bit<long long> BIT
*/
template <class T> class BIT {
private:
long long size;
vector<T> bit;
vector<T> arr;
public:
BIT(long long size) : size(size), bit(size + 1), arr(size) {}
void set(long long ind, long long val) { add(ind, val - arr[ind]); }
void add(long long ind, long long val) {
arr[ind] += val;
ind++;
for (; ind <= size; ind += ind & -ind) { bit[ind] += val; }
}
T pref_sum(long long ind) {
ind++;
T total = 0;
for (; ind > 0; ind -= ind & -ind) { total += bit[ind]; }
return total;
}
};
/*
Change Comb for specific Seg tree probs, but run with Seg<long long> Seg;
*/
template<class T> struct Seg {
const T ID = 1e18; T comb(T a, T b) { return min(a,b); }
long long n; vector<T> seg;
void init(long long _n) { n = _n; seg.assign(2*n,ID); }
void pull(long long p) { seg[p] = comb(seg[2*p],seg[2*p+1]); }
void upd(long long p, T val) {
seg[p += n] = val; for (p /= 2; p; p /= 2) pull(p); }
T query(long long l, long long r) {
T ra = ID, rb = ID;
for (l += n, r += n+1; l < r; l /= 2, r /= 2) {
if (l&1) ra = comb(ra,seg[l++]);
if (r&1) rb = comb(seg[--r],rb);
}
return comb(ra,rb);
}
};
const int N = 100001;
const int W = 200001;
vector<int> xVal(N);
vector<int> yVal(N);
vector<int> a(W);
vector<int> b(W);
int n;
int w;
vector<int> up2(N, 0);
vector<int> left2(N, 0);
vector<int> down2(N, 0);
vector<int> right2(N, 0);
bool cmp(const int& a, const int& b){
return xVal[a] < xVal[b];
}
int main(){
cin >> n;
for(int i = 1; i <= n; i++){
cin >> xVal[i] >> yVal[i];
}
cin >> w;
for(int j = 1; j <= w; j++){
cin >> a[j] >> b[j];
if(xVal[a[j]] == xVal[b[j]]){
if(yVal[a[j]] > yVal[b[j]]){
swap(a[j], b[j]);
}
down2[a[j]] = b[j];
up2[b[j]] = a[j];
}
else{
if(xVal[a[j]] > xVal[b[j]]){
swap(a[j], b[j]);
}
right2[a[j]] = b[j];
left2[b[j]] = a[j];
}
}
vector<int> dist(4 * N + 1, INT_MAX);
deque<int> dq;
vector<int> values(N);
for(int i = 0; i < n; i++){
values[i] = i + 1;
}
sort(values.begin(), values.end(), cmp);
for(int val: values){
if(dist[4 * val + 0] != INT_MAX){
continue;
}
dist[4 * val + 0] = 0;
dq.push_front(4 * val + 0);
while(!dq.empty()){
int u = dq.front();
dq.pop_front();
vector<int> R_edge;
vector<int> R_wt;
int point = u/4;
if(u % 4 == 0){
R_edge.push_back(4 * point + (u + 1) % 4);
R_wt.push_back(bool(up2[point]));
R_edge.push_back(4 * point + (u + 3) % 4);
R_wt.push_back(bool(left2[point]));
if(up2[point] != 0){
R_edge.push_back(4 * up2[point] + 3);
R_wt.push_back(0);
}
if(left2[point] != 0){
R_edge.push_back(4 * left2[point] + 1);
R_wt.push_back(0);
}
}
else if(u % 4 == 1){
R_edge.push_back(4 * point + (u + 1) % 4);
R_wt.push_back(bool(right2[point]));
R_edge.push_back(4 * point + (u + 3) % 4);
R_wt.push_back(bool(up2[point]));
if(up2[point] != 0){
R_edge.push_back(4 * up2[point] + 2);
R_wt.push_back(0);
}
if(right2[point] != 0){
R_edge.push_back(4 * right2[point] + 0);
R_wt.push_back(0);
}
}
else if(u % 4 == 2){
R_edge.push_back(4 * point + (u+1)%4);
R_wt.push_back(bool(down2[point]));
R_edge.push_back(4 * point + (u+3)%4);
R_wt.push_back(bool(right2[point]));
if(down2[point] != 0){
R_edge.push_back(4 * down2[point] + 1);
R_wt.push_back(0);
}
if(right2[point] != 0){
R_edge.push_back(4 * right2[point] + 3);
R_wt.push_back(0);
}
}
else{
R_edge.push_back(4 * point + (u + 1) % 4);
R_wt.push_back(bool(left2[point]));
R_edge.push_back(4 * point + (u + 3) % 4);
R_wt.push_back(bool(down2[point]));
if(down2[point] != 0){
R_edge.push_back(4 * down2[point] + 0);
R_wt.push_back(0);
}
if(left2[point] != 0){
R_edge.push_back(4 * left2[point] + 2);
R_wt.push_back(0);
}
}
for(int e = 0; e < R_edge.size(); e++){
int v = R_edge[e];
int w = R_wt[e];
if(dist[v] <= dist[u] + w){
continue;
}
dist[v] = dist[u] + w;
if(w == 0){
dq.push_front(v);
}
else{
dq.push_back(v);
}
}
}
}
vector<int> ans;
for(int j = 1; j <= w; j++){
if(xVal[a[j]] == xVal[b[j]]){
if(dist[4 * a[j] + 3] == dist[4*a[j] + 2]){
ans.push_back(j);
}
}
else{
if(dist[4 * a[j] + 1] == dist[4 * a[j] + 2]){
ans.push_back(j);
}
}
}
cout << ans.size() << '\n';
for(int r : ans){
cout << r << '\n';
}
}
Compilation message
flood.cpp: In function 'int main()':
flood.cpp:202:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
202 | for(int e = 0; e < R_edge.size(); e++){
| ~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
6100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
6100 KB |
Output is correct |
2 |
Correct |
5 ms |
6160 KB |
Output is correct |
3 |
Correct |
5 ms |
6192 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
6100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
6100 KB |
Output is correct |
2 |
Correct |
6 ms |
6168 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
6100 KB |
Output is correct |
2 |
Correct |
5 ms |
6160 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
6100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
6100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
6204 KB |
Output is correct |
2 |
Correct |
6 ms |
6204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
6200 KB |
Output is correct |
2 |
Correct |
6 ms |
6100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
43 ms |
6820 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
151 ms |
8680 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
131 ms |
8428 KB |
Output is correct |
2 |
Correct |
183 ms |
9696 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
187 ms |
9428 KB |
Output is correct |
2 |
Correct |
211 ms |
9880 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
193 ms |
9584 KB |
Output is correct |
2 |
Correct |
186 ms |
10380 KB |
Output is correct |