Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.*;
- import java.lang.reflect.*;
- public class Main {
- static long CURRENT_TIME_NANO = System.nanoTime();
- public static void main(String[] args) throws Exception {
- int n = next();
- int m = next();
- int[] a = new int[m];
- int[] b = new int[m];
- int[] c = new int[m];
- for (int i = 0; i < m; i++) {
- a[i] = next() - 1;
- b[i] = next() - 1;
- c[i] = next() * 10000 - 1;
- }
- long[][] len = new long[n][n];
- long inf = 1000000000000L;
- for (long[] l : len) Arrays.fill(l, inf);
- for (int i = 0; i < m; i++) {
- len[a[i]][b[i]] = Math.min(len[a[i]][b[i]], c[i]);
- len[b[i]][a[i]] = Math.min(len[b[i]][a[i]], c[i]);
- }
- long[] l = new long[n];
- Arrays.fill(l, inf);
- boolean[] take = new boolean[n];
- l[0] = 0;
- for (int i = 0; i < n; i++) {
- int v = -1;
- for (int j = 0; j < n; j++)
- if (!take[j]) if (v == -1 || l[j] < l[v]) v = j;
- take[v] = true;
- for (int j = 0; j < n; j++) if (!take[j])
- l[j] = Math.min(l[j], l[v] + len[v][j]);
- }
- long val = l[n - 1];
- int count = 0;
- while (val % 10000 != 0) {count++; val++;}
- out.println((val / 10000) + " " + count);
- out.close();
- }
- static void printtime() {System.out.println((System.nanoTime() - CURRENT_TIME_NANO)*1e-9);}
- static void nexttime() {printtime(); CURRENT_TIME_NANO = System.nanoTime();}
- static PrintWriter out = new PrintWriter(System.out);
- static BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(System.in));
- static StringTokenizer in = new StringTokenizer("");
- static String nextToken() throws Exception {
- if (!in.hasMoreTokens()) in = new StringTokenizer(bufferedreader.readLine());
- return in.nextToken();
- }
- static int next() throws Exception {return Integer.parseInt(nextToken());};
- static int[] next(int n) throws Exception {
- int[] x = new int[n];
- for (int i = 0; i < n; i++) x[i] = next();
- return x;
- }
- static int[][] next(int n, int m) throws Exception {
- int[][] x = new int[n][];
- for (int i = 0; i < n; i++) x[i] = next(m);
- return x;
- }
- static long nextl() throws Exception {return Long.parseLong(nextToken());};
- static long[] nextl(int n) throws Exception {
- long[] x = new long[n];
- for (int i = 0; i < n; i++) x[i] = nextl();
- return x;
- }
- static long[][] nextl(int n, int m) throws Exception {
- long[][] x = new long[n][];
- for (int i = 0; i < n; i++) x[i] = nextl(m);
- return x;
- }
- static double nextd() throws Exception {return Double.parseDouble(nextToken());};
- static double[] nextd(int n) throws Exception {
- double[] x = new double[n];
- for (int i = 0; i < n; i++) x[i] = nextd();
- return x;
- }
- static double[][] nextd(int n, int m) throws Exception {
- double[][] x = new double[n][];
- for (int i = 0; i < n; i++) x[i] = nextd(m);
- return x;
- }
- static String nextline() throws Exception {
- in = new StringTokenizer("");
- return bufferedreader.readLine();
- }
- static void sout(String s) {System.out.println(s);}
- static void sout(long x) {System.out.println(x);}
- static void sout(int[] x) {for (int xx : x) System.out.print(xx + " "); System.out.println();}
- static void sout(long[] x) {for (long xx : x) System.out.print(xx + " "); System.out.println();}
- static void sout(int[][] x) {for (int[] xx : x) sout(xx); System.out.println();}
- static void sout(long[][] x) {for (long[] xx : x) sout(xx); System.out.println();}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement