Language: Java

import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.container;
import std.array;
import std.math;
import std.range;
import std.typecons;

pragma(msg, min("a", "aa"));
pragma(msg, min("~", "aa"));

void main()
{
  for (;;)
  {
    int n, a, s, g;
    {
      auto i = readln.chomp.split.map!(to!int);
      n = i[0];
      a = i[1];
      s = i[2];
      g = i[3];
    }
    if (!n)
    {
      break;
    }
    alias Node = Tuple!(string, "lab", int, "dist");
    alias Adj = SList!Node;
    Adj[] adjs = new Adj[](n);
    foreach (_; 0 .. a)
    {
      int x, y;
      string lab;
      {
        auto i = readln.chomp.split;
        x = i[0].to!int;
        y = i[1].to!int;
        lab = i[2];
      }
      adjs[x].insert(Node(lab, y));
    }
    Node atom = Node("", s);
    string ans = "~";
    string loop = "~";
    BinaryHeap!(Node[], "a > b") queue = BinaryHeap!(Node[], "a > b")([]);
    queue.insert(atom);
    bool[] done = new bool[](n);
    while (queue.length)
    {
      Node node = queue.front;
      queue.popFront;
      if (node.dist == g)
      {
        ans = min(ans, node.lab);
      }
      if (done[node.dist])
      {
        loop = min(loop, node.lab);
        continue;
      }
      done[node.dist] = true;
      foreach (adj; adjs[node.dist])
      {
        Node next = Node(node.lab ~ adj.lab, adj.dist);
        queue.insert(next);
      }
    }
    if (done[g] && ans <= loop)
    {
      writeln = ans;
    }
    else
    {
      writeln = "NO";
    }
  }
}

Compiler output:
Main.java:11: error: class, interface, enum, or record expected
pragma(msg, min("a", "aa"));
^
Main.java:12: error: class, interface, enum, or record expected
pragma(msg, min("~", "aa"));
^
Main.java:20: error: not a statement
      auto i = readln.chomp.split.map!(to!int);
                                       ^
Main.java:20: error: not a statement
      auto i = readln.chomp.split.map!(to!int);
                                          ^
Main.java:30: error: not a statement
    alias Node = Tuple!(string, "lab", int, "dist");
                        ^
Main.java:30: error: not a statement
    alias Node = Tuple!(string, "lab", int, "dist");
                                       ^
Main.java:31: error: not a statement
    alias Adj = SList!Node;
                      ^
Main.java:32: error: not a statement
    Adj[] adjs = new Adj[](n);
                           ^
Main.java:33: error: as of release 9, '_' is a keyword, and may not be used as an identifier
    foreach (_; 0 .. a)
             ^
Main.java:33: error: illegal '.'
    foreach (_; 0 .. a)
                   ^
Main.java:33: error: not a statement
    foreach (_; 0 .. a)
                ^
Main.java:33: error: not a statement
    foreach (_; 0 .. a)
                     ^
Main.java:39: error: not a statement
        x = i[0].to!int;
                    ^
Main.java:40: error: not a statement
        y = i[1].to!int;
                    ^
Main.java:48: error: not a statement
    BinaryHeap!(Node[], "a > b") queue = BinaryHeap!(Node[], "a > b")([]);
    ^
Main.java:48: error: not a statement
    BinaryHeap!(Node[], "a > b") queue = BinaryHeap!(Node[], "a > b")([]);
                    ^
Main.java:48: error: not a statement
    BinaryHeap!(Node[], "a > b") queue = BinaryHeap!(Node[], "a > b")([]);
                                                         ^
Main.java:50: error: not a statement
    bool[] done = new bool[](n);
                             ^
Main.java:54: error: not a statement
      queue.popFront;
           ^
Main.java:65: error: not a statement
      foreach (adj; adjs[node.dist])
                        ^
Main.java:67: error: not a statement
        Node next = Node(node.lab ~ adj.lab, adj.dist);
                                       ^
Main.java:67: error: not a statement
        Node next = Node(node.lab ~ adj.lab, adj.dist);
                                                ^
Main.java:14: error: unnamed classes are a preview feature and are disabled by default.
void main()
^
  (use --enable-preview to enable unnamed classes)
Main.java:20: error: ';' expected
      auto i = readln.chomp.split.map!(to!int);
                                         ^
Main.java:20: error: ';' expected
      auto i = readln.chomp.split.map!(to!int);
                                             ^
Main.java:30: error: ';' expected
    alias Node = Tuple!(string, "lab", int, "dist");
                      ^
Main.java:30: error: ';' expected
    alias Node = Tuple!(string, "lab", int, "dist");
                              ^
Main.java:30: error: ';' expected
    alias Node = Tuple!(string, "lab", int, "dist");
                                          ^
Main.java:31: error: ';' expected
    alias Adj = SList!Node;
                     ^
Main.java:32: error: array dimension missing
    Adj[] adjs = new Adj[](n);
                          ^
Main.java:32: error: ';' expected
    Adj[] adjs = new Adj[](n);
                            ^
Main.java:33: error: ')' or ',' expected
    foreach (_; 0 .. a)
              ^
Main.java:33: error: ';' expected
    foreach (_; 0 .. a)
                 ^
Main.java:33: error: ';' expected
    foreach (_; 0 .. a)
                      ^
Main.java:39: error: ';' expected
        x = i[0].to!int;
                   ^
Main.java:40: error: ';' expected
        y = i[1].to!int;
                   ^
Main.java:48: error: ';' expected
    BinaryHeap!(Node[], "a > b") queue = BinaryHeap!(Node[], "a > b")([]);
              ^
Main.java:48: error: ';' expected
    BinaryHeap!(Node[], "a > b") queue = BinaryHeap!(Node[], "a > b")([]);
                      ^
Main.java:48: error: ';' expected
    BinaryHeap!(Node[], "a > b") queue = BinaryHeap!(Node[], "a > b")([]);
                                                   ^
Main.java:48: error: ';' expected
    BinaryHeap!(Node[], "a > b") queue = BinaryHeap!(Node[], "a > b")([]);
                                                           ^
Main.java:50: error: array dimension missing
    bool[] done = new bool[](n);
                            ^
Main.java:50: error: ';' expected
    bool[] done = new bool[](n);
                              ^
Main.java:65: error: ')' or ',' expected
      foreach (adj; adjs[node.dist])
                  ^
Main.java:65: error: ';' expected
      foreach (adj; adjs[node.dist])
                                   ^
Main.java:67: error: ')' or ',' expected
        Node next = Node(node.lab ~ adj.lab, adj.dist);
                                 ^
Main.java:67: error: ';' expected
        Node next = Node(node.lab ~ adj.lab, adj.dist);
                                           ^
Main.java:67: error: ';' expected
        Node next = Node(node.lab ~ adj.lab, adj.dist);
                                                     ^
47 errors