Please help me out here

I know this is a very basic blunder I’m doing but plese help me here. If I make a class of a graph then there is no issue,but when I define my graph by vector graph[N], then I can’t get pairs.first;

Work on basics!

here,
what you are doing is

for(auto pairs: graph)

so this means pair is an element of graph. what is the element of graph there, it is a vector. And therefore “pairs” is actually a vector.
And vector has no member named first.

apply it like this:

#include<bits/stdc++.h>
#define moduli 998244353
#define int long long int
#define ld long double
#define F first
#define S second
#define P pair<int,int>
#define pb push_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vb vector<bool>
#define um unordered_map

using namespace std;

const int N = 100005;
vector <vector<int>> graph(N);
vector<bool> visited(N, 0);


void addEdge(int l, int r) {
    graph[l].pb(r);
}

void dfs(int src) {
    visited[src] = 1;
    cout << src << "--->";

    for (auto child : graph[src]) {
        if (!visited[child]) {
            dfs(child);
        }
    }

}

void solve(int tc) {
    int i, j, k, n, m, ans = 0, cnt = 0, sum = 0;
    cin >> m;
    for (int i = 0; i < m; ++i)
    {
        int l, r;
        cin >> l >> r;

        addEdge(l, r);
    }

    dfs(0);

}


int32_t main()
{

    ios_base:: sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int tc = 1;
    // int t;cin>>t;while(t--)
    {
        solve(tc);
        tc++;
    }
}

see input and output here

thanks.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.