Можно проще

```python
vertexes = range(1, n+1)
graph = {v: set() for v in vertexes}
for u, v in edges:
    graph[v].add(u)
    graph[u].add(v)
```