// yukicoder: 468 役に立つ競技プログラミング実践編 // 2019.8.29 bal4u #include #include #include #if 1 #define gc() getchar_unlocked() #else #define gc() getchar() #endif int in() { // 非負整数の入力 int n = 0, c = gc(); do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0'); return n; } #define INF #define MAX 100005 int N; int hi[MAX], *to[MAX], *C[MAX]; int rhi[MAX], *rto[MAX], *rC[MAX]; int start[MAX], last[MAX]; inline static void chmax(int *a, int b) { if (*a < b) *a = b; } inline static void chmin(int *a, int b) { if (*a > b) *a = b; } // トポロジーソート 独立したモジュール void topoSort(int V) { int i, j, k; static int q[MAX], top, end; static int count[MAX]; for (i = 0; i < V; i++) for (j = 0; j < hi[i]; j++) count[to[i][j]]++; top = end = 0; for (i = 0; i < V; i++) if (!count[i]) q[end++] = i; while (top < end) { i = q[top++]; for (j = 0; j < hi[i]; j++) { k = to[i][j]; /**/ chmax(&start[k], start[i] + C[i][j]); if (--count[k] == 0) q[end++] = k; } } } void rtopoSort(int V) { int i, j, k; static int q[MAX], top, end; static int count[MAX]; for (i = 0; i < V; i++) for (j = 0; j < rhi[i]; j++) count[rto[i][j]]++; top = end = 0; for (i = 0; i < V; i++) if (!count[i]) q[end++] = i; while (top < end) { i = q[top++]; for (j = 0; j < rhi[i]; j++) { k = rto[i][j]; /**/ chmin(&last[k], last[i] - rC[i][j]); if (--count[k] == 0) q[end++] = k; } } } int main() { int i, k, a, b, c, M; int *memo, sz; N = in(), M = in(); memo = malloc(sizeof(int)*M*3); sz = 0; for (i = 0; i < M; i++) { memo[sz++] = a = in(), memo[sz++] = b = in(), memo[sz++] = in(); hi[a]++, rhi[b]++; } for (i = 0; i < N; i++) { if (hi[i]) { to[i] = malloc(hi[i]*sizeof(int)), C[i] = malloc(hi[i]*sizeof(int)); } if (rhi[i]) { rto[i] = malloc(rhi[i]*sizeof(int)), rC[i] = malloc(rhi[i]*sizeof(int)); } } memset(hi, 0, sizeof(hi)), memset(rhi, 0, sizeof(rhi)); i = 0; while (i < sz) { a = memo[i++], b = memo[i++], c = memo[i++]; k = hi[a]++, to[a][k] = b, C[a][k] = c; k = rhi[b]++, rto[b][k] = a, rC[b][k] = c; } topoSort(N); for (i = 0; i < N; i++) last[i] = start[N-1]; rtopoSort(N); k = 0; for (i = 0; i < N; i++) if (start[i] != last[i]) k++; printf("%d %d/%d\n", start[N-1], k, N); return 0; }