답안 #841894

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
841894 2023-09-02T08:12:31 Z vjudge1 Roadside Advertisements (NOI17_roadsideadverts) C++17
7 / 100
1000 ms 4824 KB
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2,fma")
#include <iostream>
#include <vector>
using namespace std;
#define ll int
bool m[50001];
ll cnt,a1,a2,a3,a4,a5;
vector<pair<ll,ll>>g[50001];
void dfs(ll v,ll p,ll sum)
{
	if(m[v])
	{
		cnt+=sum;sum=0;
	}
	for(pair<ll,ll> it:g[v])
	{
		if(it.first!=p)
		{
			dfs(it.first,v,sum+it.second);
		}
	}
}
int main()
{
	ios_base::sync_with_stdio();
    cin.tie(NULL);
    cout.tie(NULL);
    
    ll n,q,u,v,c;
    //cin>>n;
    scanf("%d",&n);
    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;
	scanf("%d",&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,-1,0);
		//printf("%d",&cnt);
		cout<<cnt<<'\n';
		
		m[a2]=m[a3]=m[a4]=m[a5]=cnt=0;
	}
}

Compilation message

roadsideadverts.cpp: In function 'int main()':
roadsideadverts.cpp:52:30: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   52 |   m[a2]=m[a3]=m[a4]=m[a5]=cnt=0;
      |                           ~~~^~
roadsideadverts.cpp:33:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
roadsideadverts.cpp:37:11: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |      scanf("%d%d%d",&u,&v,&c);
      |      ~~~~~^~~~~~~~~~~~~~~~~~~
roadsideadverts.cpp:42:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |  scanf("%d",&q);
      |  ~~~~~^~~~~~~~~
roadsideadverts.cpp:45:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |   scanf("%d%d%d%d%d",&a1,&a2,&a3,&a4,&a5);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1075 ms 4824 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 112 ms 3420 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1372 KB Output is correct
2 Execution timed out 1075 ms 4824 KB Time limit exceeded
3 Halted 0 ms 0 KB -