#line 1 "main.cpp" /** * @title Template */ #include #include #include #include #include #include #include #include #line 1 "/Users/kodamankod/Desktop/ac-library/atcoder/mincostflow" #include #line 15 "main.cpp" using i32 = std::int32_t; using i64 = std::int64_t; using u32 = std::uint32_t; using u64 = std::uint64_t; using isize = std::ptrdiff_t; using usize = std::size_t; constexpr i32 inf32 = (i32(1) << 30) - 1; constexpr i64 inf64 = (i64(1) << 62) - 1; int main() { usize N, M; std::cin >> N >> M; atcoder::mcf_graph net(N); while (M--) { usize u, v; i64 c, d; std::cin >> u >> v >> c >> d; u -= 1; v -= 1; net.add_edge(u, v, 1, c); net.add_edge(u, v, 1, d); net.add_edge(v, u, 1, c); net.add_edge(v, u, 1, d); } std::cout << net.flow(0, N - 1, 2).second << '\n'; return 0; }