#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+3;
int num[N];
vector<pair<int,int> > adj[N];

void dfs(int u, int p){
	for(auto it : adj[u]){
		if(num[it.first] != -1){
			continue;
		}
		if(num[u] == it.second){
			num[it.first] = (it.second == 1 ? 2 : 1);
		}else{
			num[it.first] = it.second;
		}
		dfs(it.first,u);
	}
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	memset(num,-1,sizeof(num));
	int n,m;
	cin >> n >> m;
	for(int i=0;i<m;i++){
		int u,v,m;
		cin >> u >> v >> m;
		u--,v--;
		adj[u].emplace_back(v,m);
		adj[v].emplace_back(u,m);
	}
	if(adj[0].empty()){
		cout << "No\n";
		return 0;
	}
	num[0] = adj[0][0].second;
	dfs(0,-1);
	bool val = true;
	for(int i=0;i<n;i++){
		if(num[i] == -1){
			val = false;
			break;
		}
	}
	if(!val){
		cout << "No\n";
	}else{
		for(int i=0;i<n;i++){
			cout << num[i] << '\n';
		}
	}
}
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(void){
    int n, m;
    cin >> n >> m;
    vector< int > a(m+1), b(m+1), c(n+1), dir(m+1, 0);
    for(int i=1;i<=m;i++) cin >> a[i] >> b[i];
    for(int i=1;i<=n;i++) cin >> c[i];

    for(int i=1;i<=m;i++){
        if(c[a[i]] > c[b[i]]){
            dir[i] = 1;
        }else if(c[a[i]] < c[b[i]]){
            dir[i] = -1;
        }
    }

    auto f = [&](auto f, int v)->void{
        for(int i=1;i<=m;i++){
            if(dir[i] != 0 || (a[i] != v && b[i] != v)) continue;
            if(a[i] == v){
                dir[i] = 1;
                f(f, b[i]);
            }
            if(b[i] == v){
                dir[i] = -1;
                f(f, a[i]);
            }
        }
    };

    for(int i=1;i<=m;i++){
        if(dir[i] != 0) continue;
        f(f, a[i]);
    }

    for(int i=1;i<=m;i++){
        cout << (dir[i] == 1 ? "->" : "<-") << endl;
    }
}
