This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
# 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 |
---|
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... |
# | 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... |