# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
234555 | doowey | Matching (COCI20_matching) | C++14 | 6 ms | 2688 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int N = (int)1e5 + 100;
vector<int> T[N];
vector<pii> sol;
map<int,int> xc,yc;
vector<int> ord;
bool vis[N];
void dfs(int u){
vis[u]=true;
ord.push_back(u);
for(auto x : T[u]){
if(!vis[x])dfs(x);
}
}
int main(){
fastIO;
int n;
cin >> n;
int x, y;
for(int i = 1 ; i <= n; i ++ ){
cin >> x >> y;
if(xc[x] == 0){
xc[x]=i;
}
else{
T[i].push_back(xc[x]);
T[xc[x]].push_back(i);
}
if(yc[y] == 0){
yc[y]=i;
}
else{
T[i].push_back(yc[y]);
T[yc[y]].push_back(i);
}
}
vector<pii> sol;
for(int i = 1; i <= n; i ++ ){
if(!vis[i]){
ord.clear();
dfs(i);
if((int)ord.size() % 2 == 1){
cout << "NE\n";
return 0;
}
else{
for(int i = 0 ; i < ord.size() ; i += 2){
sol.push_back(mp(ord[i],ord[i+1]));
}
}
}
}
cout << "DA\n";
for(auto x : sol)
cout << x.fi << " " << x.se << "\n";
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |