#include <bits/stdc++.h>
using ll = long long;
struct ops{
    ll a , b ,c;
};
int main(){
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    ll n , m;
    std::cin >> n >> m;
    if(n == 2 and m ==1 ){
    ll a , b , c;
    std::cin >> a >> b >> c;
    std::cout << c+1<< " " << c;
        }
       else{  
            std::vector<ops> op(m);
            std::vector<ll> arr(n);
            for(int i = 0 ; i < m ; i++){
                ll x , y , z;
                std::cin >> x>> y >> z;
                --x;
                --y;
                op[i].a = x;
                op[i].b = y;
                op[i].c = z;
            }
            std::sort(op.begin() , op.end() , [&]( ops lar , ops smal){
                if(lar.c == smal.c ){
                    if(lar.b == smal.b){
                           
                            return lar.a > smal.a;
                        }
                    
                    else{
                        return lar.b > smal.b;
                    }
                }
              return lar.c > smal.c ;
            });
            
          
            for(int i = 0 ; i < m ; i++){
                ll l = op[i].a;
                ll r = op[i].b;
                ll val = op[i].c;
                if(arr[l] == 0 and arr[r] == 0){
                    arr[l] = val;
                    arr[r] = val;
                }
                else if(arr[l] == 0 and arr[r] != 0){
                    arr[l] = val;
                }
                 else if(arr[l] != 0 and arr[r] == 0){
                    arr[r] = val;
                }
                
            }
            ll c = op[0].c + 1;
            for( int i = 0 ; i < n ; i++){
                if(arr[i] == 0){
                   std::cout << 1000000000 << " ";
                }
                else{
                    std::cout << arr[i] << " ";
                }
            }
        
        }
    }
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |