Submission #651926

#TimeUsernameProblemLanguageResultExecution timeMemory
651926longvuCeste (COCI17_ceste)C++14
16 / 160
691 ms131072 KiB
/** * author: longvu * created: 10/20/22 21:00:44 **/ #include<bits/stdc++.h> using namespace std; #define int long long #define sz(x) ((int)x.size()) #define all(x) (x).begin(), (x).end() const int INF = numeric_limits<int>::max(); const int naxn = (int)(209); const int naxval = (int)(20009); const int mod = 1e9 + 7; template<class X, class Y> bool maximize(X& x, const Y y) { if (y > x) {x = y; return true;} return false; } template<class X, class Y> bool minimize(X& x, const Y y) { if (y < x) {x = y; return true;} return false; } struct Node { int lab, t, c; }; vector<Node> adj[naxn]; int dp[naxn][naxval]; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; for (int i = 1; i <= m; ++i) { int u, v, t, c; cin >> u >> v >> t >> c; adj[u].push_back({v, t, c}); adj[v].push_back({u, t, c}); } priority_queue<tuple<int, int, int>, vector<tuple<int, int, int>>, greater<tuple<int, int, int>>> pq; memset(dp, 0x3f, sizeof dp); dp[1][0] = 0; pq.push({0, 1 , 0}); while (!pq.empty()) { tuple<int, int, int> u = pq.top(); pq.pop(); for (auto v : adj[get<1>(u)]) { if (get<2>(u) + v.t < naxval && minimize(dp[v.lab][get<2>(u) + v.t], v.c + get<0>(u))) { pq.push({v.c + get<0>(u), v.lab, get<2>(u) + v.t}); } } } for (int i = 2; i <= n; ++i) { int ans = INF; for (int j = 0; j < naxval; ++j) { if (dp[i][j] < naxval) { minimize(ans, j * dp[i][j]); } } cout << (ans < naxval ? ans : -1) << '\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...