// #include "race.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
// #define int ll
using db = long double;
using str = string;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using pd = pair<db, db>;
#define f first
#define s second
#define tcT template<class T
#define tcTU tcT, class U
tcT> using V = vector<T>;
tcT, size_t SZ > using AR = array<T, SZ>;
using vi = V<int>;
using vb = V<bool>;
using vl = V<ll>;
using vd = V<db>;
using vs = V<str>;
using vpi = V<pi>;
using vpl = V<pl>;
#define sz(x) ll((x).size())
#define bg(x) begin(x)
#define all(x) bg(x), end(x)
#define rall(x) x.rbegin(), x.rend()
#define sor(x) sort(all(x))
#define pb push_back
#define yes cout << "Y" << "e" << "s\n";
#define no cout << "N" << "o\n";
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = ((b)-1); i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define rep(a) F0R(_,a)
#define each(a,x) for (auto& a: x)
const int MOD = 998244353;
const int MOD98 = 998244353;
const int MX = 1e9;
// const int INF = 1e18;
const db PI = acos((db)-1);
// const int dx[] = { 1,0,-1,0 };
// const int dy[] = { 0,1,0,-1 };
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());
template<class T> using pqg = priority_queue<T, vector<T>, greater<T>>;
void setIO(string name = "") {
ios_base::sync_with_stdio(0); cin.tie(0);
if ((ll)(name.size())) {
freopen((name + ".in").c_str(), "r", stdin);
freopen((name + ".out").c_str(), "w", stdout);
}
}
template<class T> bool ckmin(T& a, const T& b) {
return b < a ? a = b, 1 : 0;
}
template<class T> bool ckmax(T& a, const T& b) {
return a < b ? a = b, 1 : 0;
}
void _print(char i) { cerr << i; }
void _print(string i) { cerr << i; }
void _print(float i) { cerr << i; }
void _print(int i) { cerr << i; }
void _print(double i) { cerr << i; }
void _print() { cerr << "\n"; };
template<typename x, typename y> void _print(pair<x, y>& t) { cerr << "{";_print(t.first);cerr << ", ";_print(t.second);cerr << "},"; }
template<typename x> void _print(x& t) { cerr << "{"; for (int i = 0;i < (int)t.size();i++) { _print(t[i]); if (i < (int)t.size() - 1) cerr << ", "; } cerr << "}"; }
template<typename x, typename... y> void _print(x a, y... b) { _print(a);if (sizeof...(b)) cerr << ", ";_print(b...); }
#define dbg(x...) cerr<<"["<<#x<<"] = [";_print(x);cerr<<"]\n";
int test;
/*
*/
int n, k;
vector<ll> d;
vector<vpi> adj;
int mini;
void dfs(int u, int p, int len = 1){
each(v, adj[u]){
if(v.f == p) continue;
d[v.f] = d[u] + v.s;
if(d[v.f] == k){
mini = min(mini, len);
}
dfs(v.f, u, len + 1);
}
}
int best_path(int N, int K, int H[][2], int L[]){
adj = vector<vpi>(N + 1);
n = N, k = K;
F0R(i, N - 1){
int u = H[i][0], v = H[i][1];
adj[u].pb({v, L[i]});
adj[v].pb({u, L[i]});
}
int ans = 1000000;
F0R(i, N){
mini = 1000000;
d = vector<ll>(N + 1, 0);
dfs(i, -1);
ans = min(mini, ans);
}
if(ans == 1000000) return -1;
return ans;
}
// signed main() {
// setIO("");
// int T = 1;
// // cin >> T;
// for (test = 1; test <= T; test++) {
// // cout << "Case #" << test << ": " << a.f << " " << a.s << "\n";
// // solve();
// int N, K; cin >> N >> K;
// int H[N][2], L[N];
// F0R(i, N - 1) cin >> H[i][0] >> H[i][1];
// F0R(i, N) cin >> L[i];
// cout << best_path(N, K, H, L);
// }
// }
Compilation message
race.cpp: In function 'void setIO(std::string)':
race.cpp:55:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
55 | freopen((name + ".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
race.cpp:56:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
56 | freopen((name + ".out").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
16 ms |
400 KB |
Output is correct |
22 |
Correct |
16 ms |
408 KB |
Output is correct |
23 |
Correct |
17 ms |
404 KB |
Output is correct |
24 |
Correct |
16 ms |
468 KB |
Output is correct |
25 |
Correct |
15 ms |
404 KB |
Output is correct |
26 |
Correct |
16 ms |
340 KB |
Output is correct |
27 |
Correct |
15 ms |
408 KB |
Output is correct |
28 |
Correct |
17 ms |
408 KB |
Output is correct |
29 |
Correct |
17 ms |
400 KB |
Output is correct |
30 |
Correct |
17 ms |
340 KB |
Output is correct |
31 |
Correct |
17 ms |
396 KB |
Output is correct |
32 |
Correct |
14 ms |
408 KB |
Output is correct |
33 |
Correct |
27 ms |
380 KB |
Output is correct |
34 |
Correct |
12 ms |
340 KB |
Output is correct |
35 |
Correct |
11 ms |
416 KB |
Output is correct |
36 |
Correct |
9 ms |
424 KB |
Output is correct |
37 |
Correct |
8 ms |
340 KB |
Output is correct |
38 |
Correct |
11 ms |
404 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Execution timed out |
3082 ms |
9052 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
16 ms |
400 KB |
Output is correct |
22 |
Correct |
16 ms |
408 KB |
Output is correct |
23 |
Correct |
17 ms |
404 KB |
Output is correct |
24 |
Correct |
16 ms |
468 KB |
Output is correct |
25 |
Correct |
15 ms |
404 KB |
Output is correct |
26 |
Correct |
16 ms |
340 KB |
Output is correct |
27 |
Correct |
15 ms |
408 KB |
Output is correct |
28 |
Correct |
17 ms |
408 KB |
Output is correct |
29 |
Correct |
17 ms |
400 KB |
Output is correct |
30 |
Correct |
17 ms |
340 KB |
Output is correct |
31 |
Correct |
17 ms |
396 KB |
Output is correct |
32 |
Correct |
14 ms |
408 KB |
Output is correct |
33 |
Correct |
27 ms |
380 KB |
Output is correct |
34 |
Correct |
12 ms |
340 KB |
Output is correct |
35 |
Correct |
11 ms |
416 KB |
Output is correct |
36 |
Correct |
9 ms |
424 KB |
Output is correct |
37 |
Correct |
8 ms |
340 KB |
Output is correct |
38 |
Correct |
11 ms |
404 KB |
Output is correct |
39 |
Execution timed out |
3082 ms |
9052 KB |
Time limit exceeded |
40 |
Halted |
0 ms |
0 KB |
- |