undirected-graph-validator.cpp 780 B

1234567891011121314151617181920212223242526272829303132
  1. #include "testlib.h"
  2. #include <set>
  3. using namespace std;
  4. int main(int argc, char *argv[]) {
  5. registerValidation(argc, argv);
  6. int n = inf.readInt(1, 1000, "n");
  7. inf.readSpace();
  8. int m = inf.readInt(0, 100000, "m");
  9. inf.readEoln();
  10. set<pair<int, int>> edges;
  11. for (int i = 0; i < m; i++) {
  12. int a = inf.readInt(1, n, "a_i");
  13. inf.readSpace();
  14. int b = inf.readInt(1, n, "b_i");
  15. inf.readEoln();
  16. ensuref(a != b, "Graph can't contain loops");
  17. ensuref(edges.count(make_pair(a, b)) == 0,
  18. "Graph can't contain multiple edges between a pair of vertices");
  19. edges.insert(make_pair(a, b));
  20. edges.insert(make_pair(b, a));
  21. }
  22. inf.readEof();
  23. }