Graph Representation with stl list

From Ta Wiki
Revision as of 00:16, 8 March 2019 by Tata (talk | contribs) (Created page with "<pre> #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]; in...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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;
}