Link to this code: https://cses.fi/paste/f00c78327a690035672d1d/
#include<iostream>
#include<vector>
#include<array>
#include<algorithm>
using namespace std;
int main(){
  int n,m;
  cin>>n>>m;
  vector<long long>dp(n+1,1e15),prev(n+1);
  vector<array<int,3>>edges(m);
  for(auto &edge:edges){
    for(int &i:edge)cin>>i;      
  } 
 dp[1]=0;
  for(int i=1;i<n;i++){
    for(auto &edge:edges){
      if(dp[edge[0]]+edge[2]<dp[edge[1]]){
        dp[edge[1]]=dp[edge[0]]+edge[2];
        prev[edge[1]]=edge[0];
      }
    }
  }
  int start=-1;
  for(auto &edge:edges){
      if(dp[edge[0]]+edge[2]<dp[edge[1]]){
         start=edge[1];
         prev[edge[1]]=edge[0];
         break;
      }
    }
  if(start==-1){
    cout<<"NO\n";
  }else{
    cout<<"YES\n";
     while(n--)start=prev[start];
     vector<int>cycle(1,start);
     start=prev[start];
     while(start!=cycle[0]){
     cycle.push_back(start);
      start=prev[start];
    }
    cycle.push_back(start);
    reverse(cycle.begin(),cycle.end());
    for(auto i:cycle)cout<<i<<" ";
  }
  return 0;
}