#include <bits/stdc++.h>
using namespace std;
// Do you think you'll ever remember me someday, or will I just fade away from your memory?
#define LIFESUCK ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll int
#define str string
#define mll map<ll, ll>
#define vll vector<ll>
#define pll pair<ll, ll>
#define fi first
#define se second
#define all(c) c.begin(), c.end()
#define pb push_back
#define debug cout << "I Love You\n";
#define fu(i, a, b) for (int i = a; i <= b; i++)
#define fd(i, b, a) for (int i = b; i >= a; i--)
#define Bitc(msk, j) ((msk >> j) & 1)
#define _log(x) 31 - __builtin_clz(x)
const ll Mod = 1e9 + 7;
const ll inf = (1ll << 30);
const ll lnf = (1ll << 60);
// When time passes and things change... will you still remember someone like me?
int64_t add(ll &a, ll b) {
a += b;
if (a >= Mod) a %= Mod;
while (a < 0) a += Mod;
return a;
}
int64_t mul(ll a, ll b) {
a = 1ll * a * b % Mod;
return a;
}
template <class X, class Y>
bool minimize(X &x, Y y) {
X eps = 1e-9;
if (x > y + eps) {
x = y;
return 1;
}
return 0;
}
template <class X, class Y>
bool maximize(X &x, Y y) {
X eps = 1e-9;
if (x + eps < y) {
x = y;
return 1;
}
return 0;
}
// I wonder… will I just become a distant memory to you one day?
#define mxn 1'00'007
#define maxN 77
ll n, m, k, q;
vector<pll> graph[maxN];
ll sad = 0;
void dfs(ll u, ll p, ll time, ll sum, ll end) {
if(u == end) {
if(time <= k) minimize(sad, sum);
return;
}
for(auto&[v, w]: graph[u]) {
if(v == p) continue;
dfs(v, u, time + 1, sum + w, end);
}
}
void lovesper(const ll &TestCase) {
cin >> n >> m;
fu(i, 1, m) {
ll u, v, w; cin >> u >> v >> w;
graph[u].pb({v, w});
// edge[i] = {u, v, w};
}
cin >> k >> q;
fu(qst, 1, q) {
ll s, t; cin >> s >> t;
sad = 1e9;
dfs(s, 0, 0, 0, t);
if(sad >= 1e9) cout << -1 << '\n';
else cout << sad << '\n';
}
// if(Love1::check()) {
// Love1::DreamyLove();
// return;
// }
}
signed main() {
LIFESUCK
#define name "lovesper"
// freopen(name".inp", "r", stdin);
// freopen(name".out", "w", stdout);
ll Test = 1;
// cin >> Test;
fu(i, 1, Test) {
lovesper(i);
if (i < Test) cout << '\n';
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp:24:21: warning: overflow in conversion from 'long long int' to 'int' changes value from '1152921504606846976' to '0' [-Woverflow]
24 | const ll lnf = (1ll << 60);
| ~~~~~^~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |