/*#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2,fma")*/
#include <bits/stdc++.h>
using namespace std;
#define ll int
map<pair<ll,ll>,ll>mp;
map<ll,ll>pm;
ll m[50010];
ll n,cnt,a1,a2,a3,a4,a5;
ll used[50010];
vector<ll>g[50010];
ll tek=0;
void dfs(ll v,ll p)
{
if(m[v]==1)
{
pm[v]=1;
}
used[v]=tek;
for(int it:g[v])
{
if(used[it]!=tek)
{
dfs(it,v);
}
}
if(pm[v]==1)
{
cnt+=mp[{p,v}];
pm[p]=max(pm[p],1);
pm[v]=2;
}
}
void anomalous_solve()
{
cin>>n;
ll q,u,v,c;
for(int i=1;i<n;i++)
{
//cin>>u>>v>>c;
scanf("%d%d%d",&u,&v,&c);
g[u].push_back(v);
g[v].push_back(u);
mp[{u,v}]=c;
mp[{v,u}]=c;
}
cin>>q;
if(q>1000)
{
exit(0);
}
while(q--)
{
tek++;
scanf("%d%d%d%d%d",&a1,&a2,&a3,&a4,&a5);
//cin>>a1>>a2>>a3>>a4>>a5;
m[a2]=m[a3]=m[a4]=m[a5]=1;
dfs(a1,-1);
cout<<cnt<<"\n";
m[a2]=m[a3]=m[a4]=m[a5]=0;
cnt=0;
pm.clear();
}
}
int main()
{
// freopen("INPUT.txt","r",stdin);
// freopen("OUTPUT.txt","w",stdout);
ios_base::sync_with_stdio();
cin.tie(NULL);
cout.tie(NULL);
ll test=1;
//cin>>test;
for(int pos=1;pos<=test;pos++)
anomalous_solve();
}
Compilation message
roadsideadverts.cpp: In function 'void anomalous_solve()':
roadsideadverts.cpp:42:11: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
42 | scanf("%d%d%d",&u,&v,&c);
| ~~~~~^~~~~~~~~~~~~~~~~~~
roadsideadverts.cpp:56:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
56 | scanf("%d%d%d%d%d",&a1,&a2,&a3,&a4,&a5);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1368 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
40 ms |
9296 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1045 ms |
12368 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1368 KB |
Output is correct |
2 |
Incorrect |
40 ms |
9296 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |