Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define INF 0x3f3f3f3f
- using namespace std;
- inline void min_self(int& a, int b) {
- a = min(a, b);
- }
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- int N;
- cin >> N;
- int cost[32][32][32], inLevel[32];
- vector < int > v[32][32];
- for(int i = 1; i <= N; ++i) {
- int K;
- cin >> K;
- inLevel[i] = K;
- for(int j = 1; j <= K; ++j)
- while(true) {
- int a, b;
- cin >> a;
- if(a == 0)
- break;
- cin >> b;
- v[i][j].push_back(a);
- cost[i][j][a] = b;
- }
- if(i == N)
- break;
- char x;
- cin >> x;
- }
- vector < vector < int > > d(32, vector < int >(32, INF));
- d[0][1] = 0;
- for(int i = 1; i <= N; ++i)
- for(int j = 1; j <= inLevel[i]; ++j)
- for(int k = 0; k < (int)v[i][j].size(); ++k) {
- int x = v[i][j][k];
- if(d[i][j] > d[i - 1][x] + cost[i][j][x])
- d[i][j] = d[i - 1][x] + cost[i][j][x];
- }
- int ans = INF;
- for(int i = 1; i <= inLevel[N]; ++i)
- min_self(ans, d[N][i]);
- cout << ans;
- }
Advertisement
Add Comment
Please, Sign In to add comment