> For the complete documentation index, see [llms.txt](https://phitron.gitbook.io/algorithm/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://phitron.gitbook.io/algorithm/module_1/_-edge.md).

# মডিউল ১\_৭ঃ Edge লিস্ট

## Edge লিস্ট

Edge লিস্ট হচ্ছে এমন একটি লিস্ট যেখানে কোন একটা গ্রাফের edge গুলো রাখা হয়।&#x20;

## গ্রাফের ইনপুট

**6 6**\ <mark style="color:blue;">0 1</mark>\ <mark style="color:blue;">1 5</mark>\ <mark style="color:blue;">0 4</mark>\ <mark style="color:blue;">0 3</mark>\ <mark style="color:blue;">3 4</mark>\ <mark style="color:blue;">2 4</mark>&#x20;

উপরের দেয়া গ্রাফের ইনপুটে গ্রাফের edge (0, 1), (1, 5), (0, 4), (0, 3), (3, 4), (2, 4) আছে, এই edge গুলোকে আমরা কোন একটি লিস্টের মধ্যে রাখবো সেইটিই হচ্ছে edge list।&#x20;

প্রতিটি edge ২টি নোড দেয়া থাকে। এই প্রতিটি edge এর নোড ২টিকে দিয়ে আমরা একটি pair\<int, int> বানিয়ে, সেই pair\<int,int> টিকে কোন একটা লিস্টের মধ্যে রাখলে লিস্টটিতে নিচে দেখানো চিত্রের মত edge থাকবে।&#x20;

<figure><img src="https://1548341763-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjliRFwU9cGQFGljHYgOZ%2Fuploads%2FYDJCvYLh2cYpOTXqKioW%2Fimage.png?alt=media&amp;token=cb7c2739-f459-4831-927c-54c756d9828e" alt=""><figcaption></figcaption></figure>

## Edge লিস্ট ইমপ্লিমেন্টশন

গ্রাফের Number of nodes (n) and Number of Edges (e) ইনপুট নেয়া হল। vector declare করা হল যেখানে pair\<int, int> কে রাখা যাবে।&#x20;

```
int n, e;
cin >> n >> e;
vector<pair<int, int>> v;
```

e বার লুপ চালিয়ে, লুপের ভিতর edge এর নোড ২টি a and b ইনপুট নিয়ে, সেইগুলো pair বানিয়ে vector এর মধ্যে পুশ করা হল।&#x20;

```
while (e--)
{
    int a, b;
    cin >> a >> b;
    v.push_back({a, b});
}
```

vector টিতে লুপ চালিয়ে edge গুলোকে acess করা হল।&#x20;

```
for (auto p : v)
{
    cout << p.first << " " << p.second << endl;
}
```

***

## সম্পূর্ণ কোড Edge লিস্ট ইমপ্লিমেন্টশন

```
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, e;
    cin >> n >> e;
    vector<pair<int, int>> v;
    while (e--)
    {
        int a, b;
        cin >> a >> b;
        v.push_back({a, b});
    }
    
    // for (int i = 0; i < v.size(); i++)
    // {
    //     cout << v[i].first << " " << v[i].second << endl;
    // }
    
    for (auto p : v)
    {
        cout << p.first << " " << p.second << endl;
    }
    return 0;
}
```
