def count_components(adj):
    """Computes the number of components of a graph from its adjacency list."""
    vis = [False] * len(adj)
    stack = []

    def fill(start):
        vis[start] = True
        stack.append(start)

        while stack:
            for neighbor in adj[stack.pop()]:
                if vis[neighbor]:
                    continue
                vis[neighbor] = True
                stack.append(neighbor)

    count = 0
    for start in range(1, len(adj)):
        if vis[start]:
            continue
        fill(start)
        count += 1

    return count