# include<bits/stdc++.h>
using namespace std;
#define ll long long
const int MAXN=1e5;
int n,a1,b1,sum,maxx;
vector<int>v[MAXN];
int a[MAXN],b[MAXN],c[MAXN],vis[MAXN];
void zero(int x){
for(int i=1;i<=n;i++) vis[i]=0;
}
int bfs(int a2,int b2,int c2){
if(vis[b2]==1){
return 0;
}
queue<int>q,us;
q.push(a2);
us.push(a2);
vis[a2]=1;
while(!q.empty()){
int qq=q.front();
q.pop();
for(auto sx:v[qq]){
if(vis[sx]==0){
vis[sx]=1;
us.push(sx);
if(sx==b2){
return c2;
}
q.push(sx);
}
}
}
while(!us.empty()){
vis[us.front()]=0;
us.pop();
}
return 0;
}
int main(){
cin>>n;
for(int i=0;i<n-1;i++){
cin>>a1>>b1;
v[a1].push_back(b1);
v[b1].push_back(a1);
}
int qw;
cin>>qw;
for(int i=0;i<qw;i++){
cin>>a[i]>>b[i]>>c[i];
}
for(int kk=0;kk<qw;kk++){
for(int i=0;i<qw;i++){
sum+=bfs(a[i],b[i],c[i]);
for(int j=kk;j<qw;j++){
sum+=bfs(a[j],b[j],c[j]);
}
maxx=max(maxx,sum);
sum=0;
zero(n);
}
}
cout<<maxx;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
3932 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
4 ms |
8028 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2024 ms |
4188 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
29 ms |
12116 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
3932 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
11 ms |
8800 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
3932 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
3932 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |