This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int n, m;
vector< vector<int> > grp;
vector<int> used;
void dfs ( int v, int p )
{
    used[v] = 1;
    for ( auto& to : grp[v] )
    if ( to != p )
    {
        if ( used[to] )
        {
            cout << "NO\n";
            exit(0);
        }
        dfs( to, v );
    }
}
int main ()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;
    grp.resize( n+1 );
    for ( int i=0; i<m; i++ )
    {
        int u, v;
        cin >> u >> v;
        grp[u].push_back( v );
        grp[v].push_back( u );
    }
    used.assign( n+1, 0 );
    dfs( 1, -1 );
    cout << "YES 0";
    return 0;
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |