#include <bits/stdc++.h>
using namespace std;
bool done[45];
int u[45],r[45], l[45],d[45];
int connect[45];
bool toret = false;
int N;
vector<pair<int,pair<int,int> > >c1;
vector<pair<int,pair<int,int> > >c2;
int X[45],Y[45];
void iterate(int n){
if (n==N){
printf("DA\n");
for (int x = 0; x<n; x++){
if (connect[x]!=-1){
printf("%d %d\n",x+1,connect[x]+1);
}
}
toret = true;
return;
}
if (u[n]!=-1){
bool can = true;
for (auto x : c2){
if (X[n]<=x.second.second && X[n]>=x.second.first && x.first<=max(Y[n],Y[u[n]]) && x.first>=min(Y[n],Y[u[n]])){
can = false;
break;
}
}
if (can && !done[u[n]]){
connect[n] = u[n];
done[n] = true;
done[u[n]] = true;
int t = n+1;
while (done[t]) t++;
//printf("connect %d %d\n",n,u[n]);
c1.push_back({X[n],{min(Y[n],Y[u[n]]),max(Y[n],Y[u[n]])}});
iterate(t);
c1.pop_back();
connect[n] = -1;
if (toret) return;
done[n] = false;
done[u[n]] = false;
}
}
if (d[n]!=-1){
bool can = true;
for (auto x : c2){
if (X[n]<=x.second.second && X[n]>=x.second.first && x.first<=max(Y[n],Y[d[n]]) && x.first>=min(Y[n],Y[d[n]])){
can = false;
break;
}
}
if (can && !done[d[n]]){
connect[n] = d[n];
done[n] = true;
done[d[n]] = true;
int t = n+1;
while (done[t]) t++;
//printf("connect %d %d\n",n,d[n]);
c1.push_back({X[n],{min(Y[n],Y[d[n]]),max(Y[n],Y[d[n]])}});
iterate(t);
c1.pop_back();
connect[n] = -1;
if (toret) return;
done[n] = false;
done[d[n]] = false;
}
}
if (r[n]!=-1){
bool can = true;
for (auto x : c1){
if (Y[n]<=x.second.second && Y[n]>=x.second.first && x.first<=max(X[n],X[r[n]]) && x.first>=min(X[n],X[r[n]])){
can = false;
break;
}
}
if (can && !done[r[n]]){
connect[n] = r[n];
done[n] = true;
done[r[n]] = true;
int t = n+1;
while (done[t]) t++;
//printf("connect %d %d\n",n,r[n]);
c2.push_back({Y[n],{min(X[n],X[r[n]]),max(X[n],X[r[n]])}});
iterate(t);
c2.pop_back();
if (toret) return;
connect[n] = -1;
done[n] = false;
done[r[n]] = false;
}
}
if (l[n]!=-1){
bool can = true;
for (auto x : c1){
if (Y[n]<=x.second.second && Y[n]>=x.second.first && x.first<=max(X[n],X[l[n]]) && x.first>=min(X[n],X[l[n]])){
can = false;
break;
}
}
if (can && !done[l[n]]){
connect[n] = l[n];
done[n] = true;
done[l[n]] = true;
int t = n+1;
while (done[t]) t++;
//printf("connect %d %d\n",n,l[n]);
c2.push_back({Y[n],{min(X[n],X[l[n]]),max(X[n],X[l[n]])}});
iterate(t);
c2.pop_back();
if (toret) return;
connect[n] = -1;
done[n] = false;
done[l[n]] = false;
}
}
}
int main(){
memset(r,-1,sizeof(r));
memset(u,-1,sizeof(u));
memset(l,-1,sizeof(l));
memset(d,-1,sizeof(d));
memset(connect,-1,sizeof(connect));
int n;
scanf("%d",&n);
N=n;
vector<pair<pair<int,int>,int> >v;
vector<pair<pair<int,int>,int> > v2;
for (int x = 0; x<n; x++){
int a,b;
scanf("%d%d",&a,&b);
v.push_back({{a,b},x});
v2.push_back({{b,a},x});
X[x] = a;
Y[x] = b;
}
sort(v.begin(),v.end());
sort(v2.begin(),v2.end());
for (int x = 1; x<n; x++){
if (v[x].first.first==v[x-1].first.first){
int t1 = v[x].second;
int t2 = v[x-1].second;
u[t1] = t2;
d[t2] = t1;
}
}
for (int x = 1; x<n; x++){
if (v2[x].first.first==v2[x-1].first.first){
int t1 = v2[x].second;
int t2 = v2[x-1].second;
r[t1] = t2;
l[t2] = t1;//printf("r %d %d\n",t1,t2);
}
}
iterate(0);
if (toret) return 0;
printf("NE");
}
Compilation message
matching.cpp: In function 'int main()':
matching.cpp:130:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&n);
~~~~~^~~~~~~~~
matching.cpp:136:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&a,&b);
~~~~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
276 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
256 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
276 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
256 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
256 KB |
Output is correct |
8 |
Correct |
5 ms |
256 KB |
Output is correct |
9 |
Correct |
4 ms |
256 KB |
Output is correct |
10 |
Correct |
5 ms |
256 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
276 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
256 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
256 KB |
Output is correct |
8 |
Correct |
5 ms |
256 KB |
Output is correct |
9 |
Correct |
4 ms |
256 KB |
Output is correct |
10 |
Correct |
5 ms |
256 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
256 KB |
Output is correct |
13 |
Runtime error |
6 ms |
640 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
276 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
256 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
256 KB |
Output is correct |
8 |
Correct |
5 ms |
256 KB |
Output is correct |
9 |
Correct |
4 ms |
256 KB |
Output is correct |
10 |
Correct |
5 ms |
256 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
256 KB |
Output is correct |
13 |
Runtime error |
6 ms |
640 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
14 |
Halted |
0 ms |
0 KB |
- |