#include <iostream>
#define Bekabot ios_base::sync_with_stdio(NULL);cin.tie(0);cout.tie(0);
#define int long long
const int N = 2e5 + 78 , inf = 1e19;
using namespace std;
string trans(int n , int k){
string s = "";
while(n != 0){
int d = n % k;
if(d < 10){
s = to_string(d) + s;
}
else{
s = char(d + 'A' - 10) + s;
}
n /= k;
}
return s;
}
int n , m , d[N] , q , sum = 0;
vector<pair<int , int>> g[N];
vector<int> ans;
int dj(int sta , int a1 , int a2 , int a3 , int a4){
for(int i = 0 ; i <= n ; i++)d[i] = inf;
d[sta] = 0;
int p[n + 1];
set<pair<int , int>> st;
st.insert({0 , sta});
while(st.size()){
int v = st.begin() -> second;
st.erase(st.begin());
for(int i = 0 ; i < g[v].size() ; i++){
int to = g[v][i].first , w = g[v][i].second;
int cur = d[v] + w;
if(d[to] > cur){
st.erase({d[to] , to});
d[to] = cur;
p[to] = v;
st.insert({d[to] , to});
}
}
}
return max(d[a1] , max(d[a2] , max(d[a3] , d[a4])));
}
void solve(){
cin >> n;
for(int i = 1 ; i < n ; i++){
int x, y , z;
cin >> x >> y >> z;
sum += z;
g[x].push_back({y , z});
g[y].push_back({x , z});
}
if(n != 5){
cin >> q;
while(q--){
int a1 , a2 , a3 , a4 , a5;
cin >> a1 >> a2 >> a3 >> a4 >> a5;
int mx = dj(a1 , a2 , a3 , a4 , a5);
mx = max(mx , dj(a2 , a3 , a4 , a5 , a1));
mx = max(mx , dj(a3 , a1 , a2 , a4 , a5));
mx = max(mx , dj(a4 , a1 , a2 , a3 , a5));
mx = max(mx , dj(a5 , a1 , a2 , a3 , a4));
cout << mx;
}
}
else{
cin >> q;
while(q--){
cout << sum << '\n';
}
}
}
main(){
Bekabot
int t = 1;
//cin >> t;
while(t--){
solve();
}
}
Compilation message
roadsideadverts.cpp:7:32: warning: overflow in conversion from 'double' to 'long long int' changes value from '1.0e+19' to '9223372036854775807' [-Woverflow]
7 | const int N = 2e5 + 78 , inf = 1e19;
| ^~~~
roadsideadverts.cpp:25:1: error: 'vector' does not name a type
25 | vector<pair<int , int>> g[N];
| ^~~~~~
roadsideadverts.cpp:26:1: error: 'vector' does not name a type
26 | vector<int> ans;
| ^~~~~~
roadsideadverts.cpp: In function 'long long int dj(long long int, long long int, long long int, long long int, long long int)':
roadsideadverts.cpp:31:3: error: 'set' was not declared in this scope
31 | set<pair<int , int>> st;
| ^~~
roadsideadverts.cpp:3:1: note: 'std::set' is defined in header '<set>'; did you forget to '#include <set>'?
2 | #include <iostream>
+++ |+#include <set>
3 |
roadsideadverts.cpp:31:21: error: expected primary-expression before '>' token
31 | set<pair<int , int>> st;
| ^~
roadsideadverts.cpp:31:24: error: 'st' was not declared in this scope; did you mean 'sta'?
31 | set<pair<int , int>> st;
| ^~
| sta
roadsideadverts.cpp:36:24: error: 'g' was not declared in this scope
36 | for(int i = 0 ; i < g[v].size() ; i++){
| ^
roadsideadverts.cpp:38:22: error: 'w' was not declared in this scope
38 | int cur = d[v] + w;
| ^
roadsideadverts.cpp: In function 'void solve()':
roadsideadverts.cpp:55:3: error: 'g' was not declared in this scope
55 | g[x].push_back({y , z});
| ^
roadsideadverts.cpp: At global scope:
roadsideadverts.cpp:80:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
80 | main(){
| ^~~~