fork download
  1. #include <cstdio>
  2. #include <algorithm>
  3. using namespace std;
  4. struct C {
  5. int a, b;
  6. } v[1000];
  7. bool cmp(C p, C q) { return p.b < q.b; }
  8. int n, m, last, res, t;
  9. int main() {
  10. scanf("%d%d", &n, &m);
  11. for (int i = 0; i < m; i++) {
  12. scanf("%d%d", &v[i].a, &v[i].b);
  13. if (v[i].a > v[i].b) swap(v[i].a, v[i].b);
  14. }
  15. sort(v, v + m, cmp);
  16. res = 1;
  17. for (int i = 0; i < m; i++) if (last <= v[i].a) last = v[i].b, res++;
  18. printf("%d", res);
  19. }
Success #stdin #stdout 0s 3352KB
stdin
7 3
1 3
2 4
5 6
stdout
3