QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#368865 | #5102. Dungeon Crawler | installb | Compile Error | / | / | C++23 | 1.4kb | 2024-03-27 17:18:07 | 2024-03-27 17:18:07 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 4005;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
vector <pair <int,int> > G[N];
int n,Q;
int dfc = 0,dfn[N],siz[N];
ll dep[N];
void init_dfs(int u,int f){
dfn[u] = ++ dfc;
siz[u] = 1;
for(auto [v,w] : G[u]){
if(v == f) continue;
dep[v] = dep[u] + w;
init_dfs(v,u);
siz[u] += siz[v];
}
}
int k,t;
ll dt,dk;
ll ans,sumw2 = 0;
void dfs(int u,int f,int dt,int dk){
if(dfn[u] <= dfn[t] && dfn[t] <= dfn[u] + siz[u] - 1) dt = dep[u];
if(dfn[u] <= dfn[k] && dfn[k] <= dfn[u] + siz[u] - 1) dk = dep[u];
int is_leaf = 1;
for(auto [v,w] : G[u]){
if(v == f) continue;
dfs(v,u,dt,dk);
is_leaf = 0;
}
if(is_leaf){
ans = min(ans,sumw2 - dep[u] + 2 * max(0ll,dk - dt));
}
}
void solve(){
cin >> n >> Q;
for(int u,v,w,i = 1;i < n;i ++){
cin >> u >> v >> w;
G[u].push_back({v,w});
G[v].push_back({u,w});
sumw2 += 2ll * w;
}
for(int s,i = 1;i <= Q;i ++){
cin >> s >> k >> t;
dfc = 0; dep[s] = 0;
init_dfs(s,0);
ans = LLINF;
dfs(s,0,1,1);
if(dfn[t] <= dfn[k] && dfn[k] <= dfn[t] + siz[t] - 1) cout << "impossible\n";
else cout << ans << '\n';
}
}
int main(){
ios::sync_with_stdio(false);
solve();
return 0;
}
Details
answer.code: In function ‘void dfs(int, int, int, int)’: answer.code:36:47: error: no matching function for call to ‘max(long long int, int)’ 36 | ans = min(ans,sumw2 - dep[u] + 2 * max(0ll,dk - dt)); | ~~~^~~~~~~~~~~~~ In file included from /usr/include/c++/13/algorithm:60, from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:51, from answer.code:1: /usr/include/c++/13/bits/stl_algobase.h:257:5: note: candidate: ‘template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)’ 257 | max(const _Tp& __a, const _Tp& __b) | ^~~ /usr/include/c++/13/bits/stl_algobase.h:257:5: note: template argument deduction/substitution failed: answer.code:36:47: note: deduced conflicting types for parameter ‘const _Tp’ (‘long long int’ and ‘int’) 36 | ans = min(ans,sumw2 - dep[u] + 2 * max(0ll,dk - dt)); | ~~~^~~~~~~~~~~~~ /usr/include/c++/13/bits/stl_algobase.h:303:5: note: candidate: ‘template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)’ 303 | max(const _Tp& __a, const _Tp& __b, _Compare __comp) | ^~~ /usr/include/c++/13/bits/stl_algobase.h:303:5: note: template argument deduction/substitution failed: answer.code:36:47: note: deduced conflicting types for parameter ‘const _Tp’ (‘long long int’ and ‘int’) 36 | ans = min(ans,sumw2 - dep[u] + 2 * max(0ll,dk - dt)); | ~~~^~~~~~~~~~~~~ In file included from /usr/include/c++/13/algorithm:61: /usr/include/c++/13/bits/stl_algo.h:5795:5: note: candidate: ‘template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)’ 5795 | max(initializer_list<_Tp> __l) | ^~~ /usr/include/c++/13/bits/stl_algo.h:5795:5: note: template argument deduction/substitution failed: answer.code:36:47: note: mismatched types ‘std::initializer_list<_Tp>’ and ‘long long int’ 36 | ans = min(ans,sumw2 - dep[u] + 2 * max(0ll,dk - dt)); | ~~~^~~~~~~~~~~~~ /usr/include/c++/13/bits/stl_algo.h:5805:5: note: candidate: ‘template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)’ 5805 | max(initializer_list<_Tp> __l, _Compare __comp) | ^~~ /usr/include/c++/13/bits/stl_algo.h:5805:5: note: template argument deduction/substitution failed: answer.code:36:47: note: mismatched types ‘std::initializer_list<_Tp>’ and ‘long long int’ 36 | ans = min(ans,sumw2 - dep[u] + 2 * max(0ll,dk - dt)); | ~~~^~~~~~~~~~~~~