# DP
#include <iostream> #include <queue> #include <algorithm> #include <vector> #include <math.h> #include <string.h> #include <string> #include <set> #include <climits> #include <stack> #include <functional> #include <map> #define INF 987654321 #define EPS 0.000001 #define MOD 100003 using namespace std; typedef pair<int, int> pa; typedef long long ll; typedef pair<ll, ll> llpa; int n, r; vector<pa> link[110]; int a, b, c, d, e; pa dp[110]; int main() { scanf("%d %d", &n, &r); for (int i = 0; i < r; i++) { scanf("%d %d %d %d %d", &a, &b, &c, &d, &e); int now = c; if (e > 10) { e -= 10; now += e*d; } link[a].push_back({ b, now }); } memset(dp, -1, sizeof(dp)); dp[1] = { 0, 1 }; deque<int>dq; dq.push_back(1); while (!dq.empty()) { int now = dq.front(); dq.pop_front(); for (pa next : link[now]) { if (dp[next.first].first == -1 || dp[next.first].first > dp[now].first + next.second || dp[next.first].first == dp[now].first + next.second && dp[next.first].second > dp[now].second) { dp[next.first].first = dp[now].first + next.second; dp[next.first].second = dp[now].second + 1; dq.push_back(next.first); } } } if (dp[n].first == -1) { printf("It is not a great way.\n"); } else { printf("%d %d\n", dp[n].first, dp[n].second); } }
'IT > BOJ' 카테고리의 다른 글
백준(BOJ) 16169 수행시간 * (0) | 2018.10.04 |
---|---|
백준(BOJ) 16168 퍼레이드 ** (0) | 2018.10.04 |
백준(BOJ) 16166 서울의 지하철 * (0) | 2018.10.04 |
백준(BOJ) 16165 걸그룹 마스터 준석이 * (0) | 2018.10.04 |
백준(BOJ) 2316 도시 왕복하기 *** (0) | 2018.10.01 |