#include <bits/stdc++.h>

/*
int minDistance(std::vector<bool> &visited, std::vector<int> &distance)
{

    int min=INFINITY;
    int min_index=0;

    for (size_t i = 0; i < visited.size(); i++)
    {
        if(!visited[i] && distance[i]<min)
        {
            min=distance[i];
            min_index=i;
        }
    }
    

    return min_index;
}
*/

void Dijkstra(std::vector<bool> &visited, std::vector<int> &distance,std::vector<std::vector<int>> &graph)
{
    int min,min_index;

    for(size_t i = 0; i < visited.size(); i++)
    {
        min=INT_MAX;

        for (size_t i = 0; i < visited.size(); i++)
        {
            if(!visited[i] && distance[i]<min)
            {
                min=distance[i];
                min_index=i;
            }
        }

        visited[min_index] = true;

        for(size_t j = 0; j < graph.size(); j++)
        {
            if(!visited[graph[j][1]]
            && graph[j][0]==min_index 
            && distance[min_index] != INT_MAX 
            && distance[min_index] + graph[j][2] < distance[graph[j][1]])
            {
                distance[graph[j][1]]=distance[min_index] + graph[j][2];
            }
        }

    }
    
}


int main()
{
    std::vector<std::vector<int>> graph;
    // node1 node2 weight

    int N,M;
    std::cin>>N>>M;
    std::vector<bool> visited(N,false);
    std::vector<int> distance(N,INT_MAX);

    for (size_t i = 0; i < M; i++)
    {
        int a,b,c;
        std::cin>>a>>b>>c;
        a--;b--;
        std::vector<int> tmp;

        tmp.push_back(a);
        tmp.push_back(b);
        tmp.push_back(c);

        graph.push_back(tmp);
        
    }

    int s,e;
    std::cin>>s>>e;
    s--;e--;

    distance[s]=0;
    
    Dijkstra(visited,distance,graph);

    for(int i : distance)
    {
        std::cout<<i++<<"\n";
    }
    
    std::cout<<distance[e]*2;
    

    return 0;
}