> 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/_-5.md).

# মডিউল ১\_৫ঃ অ্যাডজাসেন্সি লিস্ট ইমপ্লিমেন্টশন

## অ্যাডজাসেন্সি লিস্ট ইমপ্লিমেন্টশন

গ্রাফের Number of nodes (n) and Number of Edges (e) ইনপুট নেয়া হল। একটি N সাইজের  array of vector delcare করা হল।

```
int n, e;
cin >> n >> e;
vector<int> mat[n];
```

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

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

নিচের লুপটিতে অ্যারেটির 3 ইনডেক্সে থাকা vector টির মধ্যে থাকা নোড গুলোকে প্রিন্ট করা হয়েছে , সেই প্রিন্ট নোডগুলোর সাথে 3 নোডের edge রয়েছে।&#x20;

```
for (int i = 0; i < mat[3].size(); i++)
{
    cout << mat[3][i] << " ";
}
```

***

## সম্পূর্ণ কোড অ্যাডজাসেন্সি লিস্ট ইমপ্লিমেন্টশন

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