Submission #841867

# Submission time Handle Problem Language Result Execution time Memory
841867 2023-09-02T07:50:59 Z vjudge1 Roadside Advertisements (NOI17_roadsideadverts) C++17
7 / 100
1000 ms 4652 KB
#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
ll m[50010];
ll n,cnt,a1,a2,a3,a4,a5;
bool used[50010];
vector<pair<ll,ll>>g[50010];
void dfs(ll v,ll sum)
{
	if(m[v]==1)
	{
		cnt+=sum;sum=0;
	}
	//cout<<v<<" "<<sum<<"!!!\n";
	used[v]=1;
	for(pair<ll,ll> it:g[v])
	{
		if(used[it.first]!=1)
		{
			dfs(it.first,sum + it.second);
		}
	}
	//cout<<v<<" "<<sum<<"???\n";
}
int main()
{
	ios_base::sync_with_stdio();
    cin.tie(NULL);
    cout.tie(NULL);
    
    cin>>n;
    ll q,u,v,c;
    bool BANKAI=1;
    ll st=0;
    for(int i=1;i<n;i++)
    {
    	//cin>>u>>v>>c;
    	scanf("%d%d%d",&u,&v,&c);
    	g[u].push_back({v,c});
    	g[v].push_back({u,c});
	}
	cin>>q;
	while(q--)
	{
		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,0);
		cout<<cnt<<"\n";
		
		m[a2]=m[a3]=m[a4]=m[a5]=0;
		cnt=0;
		for(int i=0;i<n;i++)used[i]=0;
	}
}

Compilation message

roadsideadverts.cpp: In function 'int main()':
roadsideadverts.cpp:36:10: warning: unused variable 'BANKAI' [-Wunused-variable]
   36 |     bool BANKAI=1;
      |          ^~~~~~
roadsideadverts.cpp:37:8: warning: unused variable 'st' [-Wunused-variable]
   37 |     ll st=0;
      |        ^~
roadsideadverts.cpp:41:11: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |      scanf("%d%d%d",&u,&v,&c);
      |      ~~~~~^~~~~~~~~~~~~~~~~~~
roadsideadverts.cpp:48:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |   scanf("%d%d%d%d%d",&a1,&a2,&a3,&a4,&a5);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1056 ms 4652 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 116 ms 3700 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1368 KB Output is correct
2 Execution timed out 1056 ms 4652 KB Time limit exceeded
3 Halted 0 ms 0 KB -