ZH-Murat-004-27's blog

By ZH-Murat-004-27, history, 2 months ago, translation, In Russian

как написать графы на c++?

  • Vote: I like it
  • -14
  • Vote: I do not like it

»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it

why dislikes?

»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it

at least like that

»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it

std::cout << "graph";

»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it
vector<int> edges[200005]; // 200005 is max node amount

int main{
  int n,m; //n node amount, m edge amount
  cin>>n>>m;
  while (m--){ //repeat m times
    int a,b;
    cin>>a>>b;
    edges[a].push_back(b); //b shares an edge with a
    edges[b].push_back(a); //a shares an edge with b
  }
}

A simple implemetation of a graph(unweigthted,undirectional)

I am a beginner too. I recommend you use usaco guide to learn graph and do some practice problems.

Learn dfs,bfs,dijkstra and solve CSES graph section.

»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it

why