-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathC1237.cpp
More file actions
65 lines (49 loc) · 886 Bytes
/
Copy pathC1237.cpp
File metadata and controls
65 lines (49 loc) · 886 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pb push_back
using namespace std;
const int D = 3;
vector<vector<int>> p;
int solve(vector<int> id, int lvl)
{
if(lvl==D) return id[0];
map<int, vector<int>> mp;
for(int i: id)
{
mp[p[i][lvl]].pb(i);
}
vector<int> res;
for(auto m: mp)
{
int cur = solve(m.second, lvl+1);
if(cur != -1)
{
res.pb(cur);
}
}
for(int i = 0; i < (int)res.size() - 1; i += 2)
{
cout << res[i]+1 << ' ' << res[i+1]+1 << '\n';
}
if(res.size() & 1) return res.back();
return -1;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int n; cin >> n;
p.resize(n, vector<int>(D));
for(int i = 0; i < n; i++)
{
for(int j = 0; j < D; j++)
{
cin >> p[i][j];
}
}
vector<int> id(n);
iota(id.begin(), id.end(), 0);
solve(id, 0);
return 0;
}