#include <bits/stdc++.h>
using namespace std;
bool done[45];
int u[45],r[45];
int connect[45];
bool toret = false;
int N;
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){
if (!done[u[n]]){
connect[n] = u[n];
done[n] = true;
done[u[n]] = true;
int t = n+1;
while (done[t]) t++;
iterate(t);
connect[n] = -1;
if (toret) return;
done[n] = false;
done[u[n]] = false;
}
}
if (r[n]!=-1){
if (!done[r[n]]){
connect[n] = r[n];
done[n] = true;
done[r[n]] = true;
int t = n+1;
while (done[t]) t++;
iterate(t);
if (toret) return;
connect[n] = -1;
done[n] = false;
done[r[n]] = false;
}
}
}
int main(){
memset(r,-1,sizeof(r));
memset(u,-1,sizeof(u));
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});
}
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 = min(v[x].second,v[x-1].second);
int t2 = max(v[x].second,v[x-1].second);
u[t1] = t2;
}
}
for (int x = 1; x<n; x++){
if (v2[x].first.first==v2[x-1].first.first){
int t1 = min(v2[x].second,v2[x-1].second);
int t2 = max(v2[x].second,v2[x-1].second);
r[t1] = t2;
}
}
iterate(0);
if (toret) return 0;
printf("NE");
}
Compilation message
matching.cpp: In function 'int main()':
matching.cpp:58:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&n);
~~~~~^~~~~~~~~
matching.cpp:64:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&a,&b);
~~~~~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
4 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
4 ms |
256 KB |
Output is correct |
3 |
Correct |
4 ms |
256 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Incorrect |
5 ms |
256 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
4 ms |
256 KB |
Output is correct |
3 |
Correct |
4 ms |
256 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Incorrect |
5 ms |
256 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
4 ms |
256 KB |
Output is correct |
3 |
Correct |
4 ms |
256 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Incorrect |
5 ms |
256 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
4 ms |
256 KB |
Output is correct |
3 |
Correct |
4 ms |
256 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Incorrect |
5 ms |
256 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |