이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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
using vi = vector<int>;
using vpi = vector<pi>;
#define pb push_back
#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)
int test;
/*
*/
int n, k;
vi 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 = 1e18;
F0R(i, N){
mini = 1e18;
d = vi(N + 1, 0LL);
dfs(i, -1);
ans = min(mini, ans);
}
return (ans == 1e18 ? -1 : ans);
}
컴파일 시 표준 에러 (stderr) 메시지
race.cpp: In function 'int best_path(int, int, int (*)[2], int*)':
race.cpp:58:15: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
58 | int ans = 1e18;
| ^~~~
race.cpp:60:16: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
60 | mini = 1e18;
| ^~~~
# | 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... |