Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct Edge {
- int y, w;
- Edge *next;
- };
- struct Graph {
- Edge *edge[1 << 16];
- int degree[1 << 16], nodes, edges;
- bool directed;
- };
- void Initialize (Graph *G, bool directed) {
- G -> nodes = G -> edges = 0;
- G -> directed = directed;
- for (int i = 1; i < (1 << 16); i ++) {
- G -> degree[i] = 0;
- G -> edge[i] = nullptr;
- }
- }
- void Insert (Graph *G, int x, int y, bool directed) {
- Edge *p;
- p = new Edge;
- p -> w = NULL;
- p -> y = y;
- p -> next = G -> edge[x];
- G -> edge[x] = p;
- G -> degree[x] ++;
- if (!directed)
- Insert (G, y, x, true);
- else
- G -> edges ++;
- }
- void Read (Graph *G, bool directed) {
- Initialize (G, directed);
- int M;
- fin >> G -> nodes >> M;
- while (M --) {
- int x, y;
- fin >> x >> y;
- Insert (G, x, y, directed);
- }
- }
- void Print (Graph *G) {
- Edge *p;
- for (int i = 1; i <= G -> nodes; i ++) {
- fout << i << " : ";
- p = G -> edge[i];
- while (p != nullptr) {
- fout << p -> y << ' ';
- p = p -> next;
- }
- fout << '\n';
- }
- }
Add Comment
Please, Sign In to add comment