某OJ上的一道题
用vector存的时候WA30分,但是用链式前向星就AC了。
vector存:
vector<int> G[Maxn];
for(int y:G[x])
{
.....
}
int u,v;
G[u].push_back(v);
G[v].push_back(u);
链式前向星存:
for (int i = head[x]; i; i = nxt[i]) {
int y = to[i];
...
}
inline void add(int u, int v)
{
nxt[++tot] = head[u];
to[tot] = v;
head[u] = tot;
}
int u,v;
add(u,v);
add(v,u);
N≤105,M≤5×105 (其中 N 代表点数,其中 M 代表边数)