Skip to content

Instantly share code, notes, and snippets.

@AbhyasKanaujia
Created July 8, 2022 13:16
Show Gist options
  • Save AbhyasKanaujia/55fba13879f76e6c1ff5001c25010298 to your computer and use it in GitHub Desktop.
Save AbhyasKanaujia/55fba13879f76e6c1ff5001c25010298 to your computer and use it in GitHub Desktop.
Graph Data Structure Data Input
Input Format:

V E
u1 v1 u2 v2 ... uE vE

Where V is the number of vertices and E is the number of edges. The next line contains E pairs in the form of u v which signifies there is an edge between u and v

UNDIRECTED:

  CONNECTED:

    CYCLIC:

      NON BIPARTITE:

        5 7
        1 2 2 4 2 3 1 3 1 5 5 3 3 4

    ACYCLIC:

      BIPARTITE:

        5 4
        1 5 1 2 2 3 2 4
        1 5 1 2 2 3 2 4

  DISCONNECTED:

    CYCLIC:

      BIPARTITE:
        11 10
        1 2 2 4 3 5 5 6 5 10 6 7 10 9 7 8 9 8 8 11

DIRECTED:

  CONNECTED:

    CYCLIC:

      NON BIPARTITE

        5 7
        1 2 2 4 3 2 3 1 1 5 4 3 5 3

The input is 1 indexed. If you want 0 index then simply subtract 1 from input. In C++ you'd do:

cin >> u >> v;

adjacencyList[u - 1].push_back(v - 1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment