-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path17619.cpp
More file actions
68 lines (55 loc) · 1.25 KB
/
17619.cpp
File metadata and controls
68 lines (55 loc) · 1.25 KB
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
66
67
68
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;
#define MAXN 100050
int n,q;
int x1,x2,y;
int parent[MAXN];
struct logs {
int s,f, idx;
};
vector<logs> v;
bool cmp(logs a, logs b){
return a.s < b.s;
}
int find(int x){
if(x == parent[x]) return x;
return parent[x] = find(parent[x]);
}
void merge(int x, int y){
x = find(x);
y = find(y);
parent[x] = y;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
cin >> n >> q;
for(int i=1 ; i<=n ; i++) parent[i] = i;
for(int i=0 ; i<n ; i++){
cin >> x1 >> x2 >> y;
v.push_back({x1,x2,i+1});
}
sort(v.begin(), v.end(), cmp);
for(int i=1 ; i<v.size() ; i++){
if(v[i].s <= v[i-1].f){
merge(v[i-1].idx, v[i].idx);
v[i].f = max(v[i-1].f, v[i].f); // 다른 부분
}
}
int q1,q2;
for(int i=0 ; i<q ; i++){
cin >> q1 >> q2;
if(find(q1) == find(q2)) cout << 1 << "\n";
else cout << 0 << "\n";
}
// for(int i=0 ; i<v.size() ; i++){
// cout << v[i].s << " " << v[i].f << " "<< v[i].idx << endl;
// }
// for(int i=0 ; i<=n ; i++){
// cout << parent[i];
// }
// cout << endl;
}