Why this code is giving segmentation fault for large input (when n=200000);

This is simple program to check if input is tree.(if edges==n-1)

#include<bits/stdc++.h>
using namespace std;
const int MXN = 2e5 + 2;

vector<int> adj[MXN];
int vis[MXN];
int n;
long long edges=0;
void dfs(int x) {
    edges+=adj[x].size();
    vis[x]=1;
    for (int i=0;i<adj[x].size();i++) {
        int y=adj[x][i];
        if ( !vis[y]) {
            dfs(y);
        }
    }
}
void solve() {
    cin >> n;
    for(int i=0;i<n-1;i++ ) {
        int u, v;
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    dfs(1);
    cout<<edges/2<<endl;

}

int main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(6);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int t = 1;
    while (t--) {

        solve();

    }
}




eg test case