int n, m, cnt=0, head[MAX];
struct Edge{
int w,to,next;
}e[MAX];
void add(int from, int to, int w){
e[cnt].w = w;
e[cnt].to = to;
e[cnt].next = head[from];
head[from] = cnt++;
}
这是什么, 这是前向星。当初学算法的时候我真的怎么看都看不懂。
虽然题做对了, 但是怎么这还是晕晕糊糊的!
直到后来, 我突然悟了:
int n, m, eId = 1, getEId[MAX];
struct Edge {
int weight, to, next;
} edges[MAX];
void addEdge(int from, int to, int weight) {
edges[eId].weight = weight;
edges[eId].to = to;
edges[eId].next = getEId[from];
getEId[from] = eId++;
}
这tm不就看懂了吗?!!!