Graph Representation with stl list
Jump to navigation
Jump to search
#include <stdio.h> #include <list> using namespace std; int main(int argc, const char * argv[]) { int v,e; scanf("%d%d",&v,&e); list<int> graph[1000]; int st,en; for(int i=0;i<e;i++){ scanf("%d%d",&st,&en); graph[st].push_back(en); graph[en].push_back(st); } for(int i=0;i<v;i++){ printf("%d : ",i); for(list<int>::iterator it = graph[i].begin(); it != graph[i].end(); ++it){ printf("%d ",*it); } printf("\n"); } return 0; }