/** * @FileName a.cpp * @Author kanpurin * @Created 2020.06.03 01:52:02 **/ #include "bits/stdc++.h" using namespace std; typedef long long ll; struct DAG { private: struct Edge { int to,cost; }; std::vector> graph; bool is_dag = false; std::vector sorted; // トポロジカルソート int V; // 頂点数 public: DAG() {} DAG(int v) { assert(v > 0); V = v; graph.resize(v); } // from から to への有向辺を張る void add_edge(int from, int to,int cost) { graph[from].push_back({to,cost}); } // トポロジカルソート O(V + E) // DAG じゃないなら size 0 の vectorを返す std::vector topological_sort() { std::stack sta; //std::vector dist(V, 0);//その頂点までの最長路 std::vector in(V, 0);// 入次数 int used_cnt = 0;//使用した頂点の数 for (int i = 0; i < V; i++) { for (Edge e : graph[i]) { in[e.to]++; } } for (int i = 0; i < V; i++) if (in[i] == 0) { sta.push(i); used_cnt++; } while (!sta.empty()) { int p = sta.top(); sta.pop(); sorted.push_back(p); for (Edge e : graph[p]) { int v = e.to; in[v]--; //dist[v] = std::max(dist[v], dist[p] + 1); if (in[v] == 0) { sta.push(v); used_cnt++; } } } if (used_cnt == V) { return sorted; } else { return std::vector(0); } } vector& operator[](int x) { return graph[x]; } }; vector>> G; vector used; vector dp; DAG g; int cnt; void dfs(int v, int p = -1) { for(auto e : G[v]) { if (e.first == p) continue; if (!used[e.first] && dp[v] - dp[e.first] == e.second) { used[e.first] = true; dfs(e.first,v); cnt++; } } } int main() { int n;cin >> n; int m;cin >> m; G.resize(n); g = DAG(n); for (int i = 0; i < m; i++) { int a,b,c;cin >> a >> b >> c; g.add_edge(a,b,c); G[a].push_back({b,c}); G[b].push_back({a,c}); } auto vec = g.topological_sort(); dp.resize(n,0); for(int v : vec) { for(auto e : g[v]) { if (dp[e.to] < dp[v] + e.cost) { dp[e.to] = dp[v] + e.cost; } } } used.resize(n,false); used[n-1] = true; cnt++; dfs(n-1); cout << dp[n-1] << " " << n - cnt << "/" << n << endl; return 0; }