-
Notifications
You must be signed in to change notification settings - Fork 0
/
Building Bridges.cpp
53 lines (47 loc) · 961 Bytes
/
Building Bridges.cpp
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
/*
1
4
6 2
4 3
2 6
1 5
*/
#include<bits/stdc++.h>
#define pii pair<int, int>
using namespace std;
int countBridge(int);
bool myComp(pii, pii);
int main(){
int t, n;
cin >> t;
while(t--){
cin >> n;
cout << countBridge(n) << endl;
}
return 0;
}
bool myComp(pii a, pii b){
if(a.first == b.first)
return a.second < b.second;
else
return a.first < b.first;
}
int countBridge(int n){
pii arr[n];
int load[n];
for(int i = 0; i < n; i++){
int a, b;
cin >> a >> b;
arr[i] = {a, b};
load[i] = 1;
}
sort(arr, arr + n, myComp);
for(int i = 1; i < n; i++)
for(int j = 0; j < i; j++){
bool a = arr[i].first < arr[j].first;
bool b = arr[i].second < arr[j].second;
if(((a && b) || (!a && !b)) && load[j] + 1 > load[i])
load[i] = load[j] + 1;
}
return *max_element(load, load + n);
}