Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.IO;
- public class Graph
- {
- private int[][] g;
- private int size;
- public Graph(int size)
- {
- this.size = size;
- g = new int[size][];
- for (int i = 0; i < size; ++i)
- g[i] = new int[size];
- }
- public Graph(int[][] G)
- {
- size = G.Length;
- g = new int[size][];
- for (int i = 0; i < size; ++i)
- g[i] = new int[size];
- for (int i = 0; i < size; ++i)
- for (int j = 0; j < size; ++j)
- g[i][j] = G[i][j];
- }
- public Graph() { }
- public void Add(int v, int to)
- {
- v--; to--;
- g[v][to] = 1;
- }
- public void Remove(int v, int to)
- {
- v--; to--;
- g[v][to] = 0;
- }
- public void Print()
- {
- for (int i = 0; i < size; ++i)
- {
- for (int j = 0; j < size; ++j)
- Console.Write(g[i][j] + " ");
- Console.WriteLine();
- }
- }
- public void Clear()
- {
- for (int i = 0; i < size; ++i)
- for (int j = 0; j < size; ++j)
- g[i][j] = 0;
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- int n = 5;
- Graph gr = new Graph(n);
- gr.Add(1, 3);
- gr.Add(1, 5);
- gr.Add(1, 1);
- gr.Add(1, 2);
- gr.Add(1, 4);
- gr.Add(2, 3);
- gr.Add(4, 3);
- gr.Add(5, 3);
- gr.Add(5, 1);
- gr.Add(3, 1);
- gr.Add(2, 5);
- gr.Add(1, 4);
- gr.Add(4, 3);
- gr.Add(4, 2);
- gr.Add(5, 5);
- gr.Add(3, 5);
- gr.Print();
- Console.WriteLine("============================================");
- int a = 2;
- int b = 3;
- gr.Remove(a, b);
- gr.Print();
- int[][] m = new int[3][];
- m[0] = new int[] { 0, 0, 1 };
- m[1] = new int[] { 1, 0, 1 };
- m[2] = new int[] { 0, 1, 1 };
- gr = new Graph(m);
- Console.WriteLine("============================================");
- gr.Remove(a, b);
- gr.Print();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement