#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define ll long long
#define pb push_back
#define sz(x) (int)(x).size()
#define mp make_pair
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define D(x) cerr << #x << " is " << (x) << "\n";
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; ///find_by_order(),order_of_key()
template<class T1, class T2> ostream& operator<<(ostream& os, const pair<T1,T2>& a) { os << '{' << a.f << ", " << a.s << '}'; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& a){os << '{';for(int i=0;i<sz(a);i++){if(i>0&&i<sz(a))os << ", ";os << a[i];}os<<'}';return os;}
template<class T> ostream& operator<<(ostream& os, const set<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T> ostream& operator<<(ostream& os, const multiset<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T1,class T2> ostream& operator<<(ostream& os, const map<T1,T2>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
const int N=1e5;
vector<vector<pair<int,int> > > nxt(N,vector<pair<int,int> >(4,{-1,-1}));
vector<pair<pair<int,int>,int> > nodes;
vector<int> ans,visited(N);
int nasao=-1;
void dfs(int tr,int dir)
{
if(visited[tr])
{
nasao=tr;
return;
}
visited[tr]=1;
for(int k=0;k<4;k++)
{
int l=(dir+1-k+4)%4;
int sl=nxt[tr][l].f;
if(sl==-1)
continue;
int i=nxt[tr][l].s;
nxt[tr][l]={-1,-1};
nxt[sl][(l+2)%4]={-1,-1};
dfs(sl,l);
if(nasao==-1)
{
ans.pb(i);
continue;
}
if(nasao==tr){
nasao=-1;
continue;
}
visited[tr]=0;
return;
}
visited[tr]=0;
}
void doit(int tr)
{
dfs(tr,0);
nasao=-1;
}
int main()
{
//freopen("flood.in.14b","r",stdin);
int n;
scanf("%i",&n);
nodes.resize(n);
for(int i=0;i<n;i++)
scanf("%i %i",&nodes[i].f.f,&nodes[i].f.s),nodes[i].s=i;
int w;
scanf("%i",&w);
for(int i=1;i<=w;i++)
{
int a,b;
scanf("%i %i",&a,&b);
a--;b--;
if(nodes[a].f.f==nodes[b].f.f)
{
if(nodes[a].f.s>nodes[b].f.s)
swap(a,b);
assert(nxt[a][0].f==-1);
assert(nxt[b][2].f==-1);
nxt[a][0]={b,i};
nxt[b][2]={a,i};
}
else
{
if(nodes[a].f.f>nodes[b].f.f)
swap(a,b);
assert(nxt[a][1].f==-1);
assert(nxt[b][3].f==-1);
nxt[a][1]={b,i};
nxt[b][3]={a,i};
}
}
sort(nodes.rbegin(),nodes.rend());
for(auto p:nodes)
doit(p.s);
/*while(nodes.size())
doit(nodes.back().s);*/
printf("%i\n",ans.size());
for(auto p:ans)
printf("%i\n",p);
return 0;
}
Compilation message
flood.cpp: In function 'int main()':
flood.cpp:108:29: warning: format '%i' expects argument of type 'int', but argument 2 has type 'std::vector<int>::size_type {aka long unsigned int}' [-Wformat=]
printf("%i\n",ans.size());
~~~~~~~~~~^
flood.cpp:73:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%i",&n);
~~~~~^~~~~~~~~
flood.cpp:76:51: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%i %i",&nodes[i].f.f,&nodes[i].f.s),nodes[i].s=i;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~
flood.cpp:78:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%i",&w);
~~~~~^~~~~~~~~
flood.cpp:82:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%i %i",&a,&b);
~~~~~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
7800 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
7800 KB |
Output is correct |
2 |
Correct |
13 ms |
7804 KB |
Output is correct |
3 |
Correct |
13 ms |
7800 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
7800 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
7800 KB |
Output is correct |
2 |
Correct |
13 ms |
7800 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
7800 KB |
Output is correct |
2 |
Correct |
13 ms |
7804 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
7800 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
7800 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
7800 KB |
Output is correct |
2 |
Correct |
13 ms |
7812 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
7800 KB |
Output is correct |
2 |
Correct |
12 ms |
7800 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
33 ms |
8696 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
65 ms |
12884 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
66 ms |
11028 KB |
Output is correct |
2 |
Correct |
154 ms |
12680 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
136 ms |
12408 KB |
Output is correct |
2 |
Correct |
153 ms |
12712 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
145 ms |
12684 KB |
Output is correct |
2 |
Correct |
138 ms |
20332 KB |
Output is correct |