Acwing algorithm basic course graph theory


Graphs can be stored in adjacency tables,

The adjacency list is n linked lists,

Linked list can be simulated with array (faster than vector).

const int N;

int h[N],e[N],ne[N],idx;// Respectively, H [i]: the head node numbered I in the figure, E [i]: the value (number) of node i, and NE [i] the IDX of the next node of node i in the linked list.

void add(int a,int b)








(nodes in different linked lists can have the same value, indicating the node number. Use ne [IDX] to find the next adjacent point of the current point and H [E [IDX]] to find the adjacent point of the adjacent contact)

Recommended Today

Strong, copy difference

Strong, how is copy different? Practice makes true knowledge! Upper code strong #import “ViewController.h” @interface ViewController () @property (nonatomic,strong)NSString *name; @end @implementation ViewController – (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. Nsmutablestring * string = [[nsmutablestring alloc] initwithstring: @ “Zhang San”]; = string; Nslog (@ “string:% @, address:% […]