# Graph - 圖

## 程式實現

#### Python

g = [[0 for _ in range(V)] for _ in range(V)]


#### Java

/* Java Definition */
int[][] g = new int[V][V];


#### C++

vector<vector<int>> g (V, vector<int>(V, 0));


### 有向圖

#### Python

class DirectedGraphNode:
def __init__(self, x):
self.label = x
self.neighbors = []


#### Java

/* Java Definition */
class DirectedGraphNode {
int label;
ArrayList<DirectedGraphNode> neighbors;
DirectedGraphNode(int x) {
label = x;
neighbors = new ArrayList<DirectedGraphNode>();
}
}


#### C++

struct DirectedGraphNode {
int label;
vector<DirectedGraphNode*> neighbors;

DirectedGraphNode(int x): label(x) { }
};


### 無向圖同上，只不過在建圖時雙向同時加。

#### Python

class UndirectedGraphNode:
def __init__(self, x):
self.label = x
self.neighbors = []


#### Java

class UndirectedGraphNode {
int label;
ArrayList<UndirectedGraphNode> neighbors;
UndirectedGraphNode(int x) {
this.label = x;
this.neighbors = new ArrayList<UndirectedGraphNode>();
}
}


#### C++

struct UndirectedGraphNode {
int label;
vector<UndirectedGraphNode*> neighbors;

UndirectedGraphNode(int x): label(x) { }
};