-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path12763_dfs.cpp
53 lines (52 loc) · 1.06 KB
/
12763_dfs.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// 210523 #12763 Áö°¢ÇÏ¸é ¾ÈµÅ Gold II
// dfs (visit two_memsion)
// dijkstra + dp: 8ms
// dijkstra : 32ms
// dfs: 184ms
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <cstring>
using namespace std;
typedef pair<pair<int, int>, int> pi;
typedef long long ll;
const int MAX = 101;
const int INF = 0x3f3f3f3f;
int N, T, M, L, ans = INF;
vector<pi> v[MAX];
bool visit[MAX][10001];
void dfs(int cur, int time, int cost) {
visit[cur][0] = true;
if (cur == N) {
ans = min(ans, cost);
return;
}
for (auto i : v[cur]) {
int nTime = time + i.first.first;
if (!visit[i.first.second][nTime]) {
int next = i.first.second;
int nCost = cost + i.second;
if (nTime > T || nCost > M)
continue;
dfs(next, nTime, nCost);
}
}
}
int main() {
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(false);
cin >> N >> T >> M >> L;
while (L--) {
int a, b, t, c;
cin >> a >> b >> t >> c;
v[a].push_back({ {t, b}, c });
v[b].push_back({ {t, a}, c });
}
dfs(1, 0, 0);
if (ans >= INF)
cout << -1 << "\n";
else
cout << ans << "\n";
}