Language: Java

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.InputMismatchException;

public class Main {
	static InputStream is;
	static PrintWriter out;
	static String INPUT = "";
	
	static void solve()
	{
		int n = ni(), m = ni();
		int S = ni()-1, T = ni()-1;
		int[] from = new int[m];
		int[] to = new int[m];
		int[] w = new int[m];
		for(int i = 0;i < m;i++){
			from[i] = ni()-1;
			to[i] = ni()-1;
			w[i] = ni();
		}
		
		long ans = 0;
		int[][][] g = packWU(n, from, to, w);
		long[][] ress = dijkl(g, S);
		long[][] rest = dijkl(g, T);
		long[] ds = ress[0], nums = ress[1];
		long[] dt = rest[0], numt = rest[1];
		
		long D = ds[T];
		{
			nums = new long[n];
			nums[S] = 1;
			long[][] dds = new long[n][];
			for(int i = 0;i < n;i++){
				dds[i] = new long[]{i, ds[i]};
			}
			Arrays.sort(dds, new Comparator<long[]>() {
				public int compare(long[] a, long[] b) {
					return Long.compare(a[1], b[1]);
				}
			});
			for(int i = 0;i < n;i++){
				int cur = (int)dds[i][0];
				for(int[] e : g[cur]){
					if(ds[e[0]] == ds[cur] + e[1] && ds[e[0]] + dt[e[0]] == D){
						nums[e[0]] += nums[cur];
						nums[e[0]] %= mod;
					}
				}
			}
		}
		{
			numt = new long[n];
			numt[T] = 1;
			long[][] dds = new long[n][];
			for(int i = 0;i < n;i++){
				dds[i] = new long[]{i, dt[i]};
			}
			Arrays.sort(dds, new Comparator<long[]>() {
				public int compare(long[] a, long[] b) {
					return Long.compare(a[1], b[1]);
				}
			});
			for(int i = 0;i < n;i++){
				int cur = (int)dds[i][0];
				for(int[] e : g[cur]){
					if(dt[e[0]] == dt[cur] + e[1] && ds[e[0]] + dt[e[0]] == D){
						numt[e[0]] += numt[cur];
						numt[e[0]] %= mod;
					}
				}
			}
		}
		
		for(int i = 0;i < n;i++){
			if(ds[i]+dt[i] != D)continue;
			if(ds[i] == dt[i]){
				long u = nums[i]*numt[i]%mod;
				ans += u*u;
				ans %= mod;
			}
			if(ds[i] < dt[i]){
				for(int[] e : g[i]){
					if(ds[e[0]]+dt[e[0]] == D && ds[e[0]] > dt[e[0]]){
						long u = nums[i]*numt[e[0]]%mod;
						ans += u*u;
						ans %= mod;
					}
				}
			}
		}
		
		for(int i = 0;i < n;i++){
			if(ds[i]+dt[i] != D)continue;
			if(ds[i] == dt[i]){
				long u = nums[i]*numt[i]%mod;
				ans += u*u;
				ans %= mod;
			}
			if(ds[i] < dt[i]){
				for(int[] e : g[i]){
					if(ds[e[0]] == ds[cur] + e[1] && ds[e[0]]+dt[e[0]] == D && ds[e[0]] > dt[e[0]]){
						long u = nums[i]*numt[e[0]]%mod;
						ans += u*u;
						ans %= mod;
					}
				}
			}
		}
		ans = nums[T]*nums[T]-ans;
		ans %= mod;
		if(ans < 0)ans += mod;
		out.println(ans);
	}
	
	static int mod = 1000000007;
	
	public static long[][] dijkl(int[][][] g, int from)
	{
		int n = g.length;
		long[] td = new long[n];
		long[] tnum = new long[n];
		
		Arrays.fill(td, Long.MAX_VALUE / 2);
		MinHeapL q = new MinHeapL(n);
		q.add(from, 0);
		td[from] = 0;
		tnum[from] = 1;
		
		while(q.size() > 0){
			int cur = q.argmin();
			q.remove(cur);
			
			for(int[] e : g[cur]){
				int next = e[0];
				long nd = td[cur] + e[1];
				if(nd < td[next]){
					td[next] = nd;
					tnum[next] = tnum[cur];
					q.update(next, nd);
				}else if(nd == td[next]){
					tnum[next] += tnum[cur];
					if(tnum[next] >= mod)tnum[next] -= mod;
				}
			}
		}
		
		return new long[][]{td, tnum};
	}
	
	public static class MinHeapL {
		public long[] a;
		public int[] map;
		public int[] imap;
		public int n;
		public int pos;
		public static long INF = Long.MAX_VALUE;
		
		public MinHeapL(int m)
		{
			n = Integer.highestOneBit((m+1)<<1);
			a = new long[n];
			map = new int[n];
			imap = new int[n];
			Arrays.fill(a, INF);
			Arrays.fill(map, -1);
			Arrays.fill(imap, -1);
			pos = 1;
		}
		
		public long add(int ind, long x)
		{
			int ret = imap[ind];
			if(imap[ind] < 0){
				a[pos] = x; map[pos] = ind; imap[ind] = pos;
				pos++;
				up(pos-1);
			}
			return ret != -1 ? a[ret] : x;
		}
		
		public long update(int ind, long x)
		{
			int ret = imap[ind];
			if(imap[ind] < 0){
				a[pos] = x; map[pos] = ind; imap[ind] = pos;
				pos++;
				up(pos-1);
			}else{
				a[ret] = x;
				up(ret);
				down(ret);
			}
			return x;
		}
		
		public long remove(int ind)
		{
			if(pos == 1)return INF;
			if(imap[ind] == -1)return INF;
			
			pos--;
			int rem = imap[ind];
			long ret = a[rem];
			map[rem] = map[pos];
			imap[map[pos]] = rem;
			imap[ind] = -1;
			a[rem] = a[pos];
			a[pos] = INF;
			map[pos] = -1;
			
			up(rem);
			down(rem);
			return ret;
		}
		
		public long min() { return a[1]; }
		public int argmin() { return map[1]; }
		public int size() {	return pos-1; }
		
		private void up(int cur)
		{
			for(int c = cur, p = c>>>1;p >= 1 && a[p] > a[c];c>>>=1, p>>>=1){
				long d = a[p]; a[p] = a[c]; a[c] = d;
				int e = imap[map[p]]; imap[map[p]] = imap[map[c]]; imap[map[c]] = e;
				e = map[p]; map[p] = map[c]; map[c] = e;
			}
		}
		
		private void down(int cur)
		{
			for(int c = cur;2*c < pos;){
				int b = a[2*c] < a[2*c+1] ? 2*c : 2*c+1;
				if(a[b] < a[c]){
					long d = a[c]; a[c] = a[b]; a[b] = d;
					int e = imap[map[c]]; imap[map[c]] = imap[map[b]]; imap[map[b]] = e;
					e = map[c]; map[c] = map[b]; map[b] = e;
					c = b;
				}else{
					break;
				}
			}
		}
	}

	
	public static int[][][] packWU(int n, int[] from, int[] to, int[] w) {
		int[][][] g = new int[n][][];
		int[] p = new int[n];
		for (int f : from)
			p[f]++;
		for (int t : to)
			p[t]++;
		for (int i = 0; i < n; i++)
			g[i] = new int[p[i]][2];
		for (int i = 0; i < from.length; i++) {
			--p[from[i]];
			g[from[i]][p[from[i]]][0] = to[i];
			g[from[i]][p[from[i]]][1] = w[i];
			--p[to[i]];
			g[to[i]][p[to[i]]][0] = from[i];
			g[to[i]][p[to[i]]][1] = w[i];
		}
		return g;
	}

	
	public static void main(String[] args) throws Exception
	{
		long S = System.currentTimeMillis();
		is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);
		
		solve();
		out.flush();
		long G = System.currentTimeMillis();
		tr(G-S+"ms");
	}
	
	private static boolean eof()
	{
		if(lenbuf == -1)return true;
		int lptr = ptrbuf;
		while(lptr < lenbuf)if(!isSpaceChar(inbuf[lptr++]))return false;
		
		try {
			is.mark(1000);
			while(true){
				int b = is.read();
				if(b == -1){
					is.reset();
					return true;
				}else if(!isSpaceChar(b)){
					is.reset();
					return false;
				}
			}
		} catch (IOException e) {
			return true;
		}
	}
	
	private static byte[] inbuf = new byte[1024];
	static int lenbuf = 0, ptrbuf = 0;
	
	private static int readByte()
	{
		if(lenbuf == -1)throw new InputMismatchException();
		if(ptrbuf >= lenbuf){
			ptrbuf = 0;
			try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
			if(lenbuf <= 0)return -1;
		}
		return inbuf[ptrbuf++];
	}
	
	private static boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
//	private static boolean isSpaceChar(int c) { return !(c >= 32 && c <= 126); }
	private static int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }
	
	private static double nd() { return Double.parseDouble(ns()); }
	private static char nc() { return (char)skip(); }
	
	private static String ns()
	{
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while(!(isSpaceChar(b))){
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	
	private static char[] ns(int n)
	{
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while(p < n && !(isSpaceChar(b))){
			buf[p++] = (char)b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}
	
	private static char[][] nm(int n, int m)
	{
		char[][] map = new char[n][];
		for(int i = 0;i < n;i++)map[i] = ns(m);
		return map;
	}
	
	private static int[] na(int n)
	{
		int[] a = new int[n];
		for(int i = 0;i < n;i++)a[i] = ni();
		return a;
	}
	
	private static int ni()
	{
		int num = 0, b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}
		
		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}
	
	private static long nl()
	{
		long num = 0;
		int b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}
		
		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}
	
	private static void tr(Object... o) { if(INPUT.length() != 0)System.out.println(Arrays.deepToString(o)); }
}


Compiler output:
Main.java:107: error: cannot find symbol
					if(ds[e[0]] == ds[cur] + e[1] && ds[e[0]]+dt[e[0]] == D && ds[e[0]] > dt[e[0]]){
					                  ^
  symbol:   variable cur
  location: class Main
1 error