undirected-graph-validator.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #include "testlib.h"
  2. #include <iostream>
  3. #include <sstream>
  4. #include <fstream>
  5. #include <iomanip>
  6. #include <string>
  7. #include <cstdlib>
  8. #include <cstdio>
  9. #include <cstring>
  10. #include <cmath>
  11. #include <ctime>
  12. #include <climits>
  13. #include <cassert>
  14. #include <vector>
  15. #include <queue>
  16. #include <stack>
  17. #include <deque>
  18. #include <set>
  19. #include <map>
  20. #include <bitset>
  21. #include <utility>
  22. #include <algorithm>
  23. #define forn(i, n) for (int i = 0; i < int(n); i++)
  24. using namespace std;
  25. int main(int argc, char* argv[])
  26. {
  27. registerValidation(argc, argv);
  28. int n = inf.readInt(1, 1000, "n");
  29. inf.readSpace();
  30. int m = inf.readInt(0, 100000, "m");
  31. inf.readEoln();
  32. set<pair<int,int> > edges;
  33. forn(i, m)
  34. {
  35. int a = inf.readInt(1, n, "a_i");
  36. inf.readSpace();
  37. int b = inf.readInt(1, n, "b_i");
  38. inf.readEoln();
  39. ensuref(a != b, "Graph can't contain loops");
  40. ensuref(edges.count(make_pair(a, b)) == 0, "Graph can't contain multiple edges between a pair of vertices");
  41. edges.insert(make_pair(a, b));
  42. edges.insert(make_pair(b, a));
  43. }
  44. inf.readEof();
  45. return 0;
  46. }