daily pastebin goal
7%
SHARE
TWEET

Cin directed and non-directed edges

a guest Jan 20th, 2018 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <vector>
  4. using namespace std;
  5.  
  6. #define MAX_N 100000
  7.  
  8.  
  9. typedef struct { void *g; } nedge_t;
  10. typedef struct { void *g; } dedge_t;
  11.  
  12. struct Graph {
  13.     vector<int> edges[MAX_N];
  14.     nedge_t n_edge;
  15.     dedge_t d_edge;
  16.  
  17.     Graph() {
  18.         n_edge.g = this;
  19.         d_edge.g = this;
  20.     }
  21. };
  22.  
  23. inline istream& operator>>(istream& in, nedge_t& e) {
  24.     int tmp1, tmp2;
  25.     in >> tmp1 >> tmp2;
  26.     ((Graph*) (e.g))->edges[--tmp1].push_back(--tmp2);
  27.     ((Graph*) (e.g))->edges[tmp2].push_back(tmp1);
  28.     return in;
  29. }
  30.  
  31. inline istream& operator>>(istream& in, dedge_t& e) {
  32.     int tmp1, tmp2;
  33.     in >> tmp1 >> tmp2;
  34.     ((Graph*) (e.g))->edges[--tmp1].push_back(--tmp2);
  35.     return in;
  36. }
  37.  
  38. int main() {
  39.     freopen("input.txt", "r", stdin);
  40.     ios_base::sync_with_stdio(0);
  41.     cin.tie(0);
  42.  
  43.     int n, m;
  44.     cin >> n >> m;
  45.  
  46.     Graph g;
  47.     for(int i(0); i < m; ++i)
  48.         cin >> g.d_edge;
  49.     return 0;
  50. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top