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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
| #include<iostream> #include<cstring> #include<string> #include<cstdio> #include<algorithm> #include<vector>
const int N = 6;
using namespace std;
int n;
struct node { int l, r; int num; int i; }a[N];
int e[N], ne[N], h[N], idx; bool t[N],st[N][N];
void add(int a, int b) { e[idx] = b; ne[idx] = h[a]; h[a] = idx++; }
bool cmp(node a, node b) { return a.num > b.num; }
bool f() { for (int i = 0; i < n; i++) { if (t[i]) continue; for (int j = h[a[i].i]; j!=-1; j = ne[j]) { if (t[e[j]])continue; return false; } }
return true; }
int main() { cin >> n;
memset(h, -1, sizeof(h));
for (int i = 0; i < n; i++) { int x, y; cin >> x >> y; a[i].l = min(x, y); a[i].r = max(x, y); a[i].i = i; }
int sum = 0;
for (int i = 0; i < n; i++) { int z = 0; for (int j = 0; j < n; j++) { if (j == i)continue; if (!(a[j].r<a[i].l || a[j].l>a[i].r)) { add(i, j); a[i].num++; } } }
sort(a, a + n, cmp);
int ans = 0;
if (f()) { cout << 0; return 0; } else { for (int i = 0; i < n; i++) { t[i] = true; ans++; if (f()) { break; }
} } cout << ans;
return 0; }
|