Submission #840260

# Submission time Handle Problem Language Result Execution time Memory
840260 2023-08-31T08:53:44 Z Lib Closing Time (IOI23_closing) C++17
8 / 100
140 ms 31432 KB
#include "closing.h"
#include <bits/stdc++.h>
using namespace std;
//long long U[200003];
//long long V[200003];
//long long W[200003];
int max_score(int N, int X, int Y, long long K, std::vector<int> U, std::vector<int> V, std::vector<int> W)
{
	vector <pair <int,long long> > temp;
	int check[200003];
	vector <vector <pair <int,long long> > > adj;
	int n=N;
	int x=X;
	int y=Y;
	long long k=K;
	for(int i=0;i<=n;i++){
		adj.push_back(temp);
	}
	vector <pair <int, long long> > clist;
	vector <long long> dist;
	for(int i=0;i<n-1;i++){
		//cin>>U[i]>>V[i]>>W[i];
		adj[U[i]].push_back({V[i],W[i]});
		adj[V[i]].push_back({U[i],W[i]});
	}
	int cnt=0;
	cnt=0;
	for(int i=0;i<n;i++){
		check[i]=0;
	}
	clist.push_back({x,0});
	dist.push_back(0);
	check[x]=1;
	while(cnt<clist.size()){
		for(int i=0;i<adj[clist[cnt].first].size();i++){
			if(check[adj[clist[cnt].first][i].first]==0){
				check[adj[clist[cnt].first][i].first]=1;
				clist.push_back({adj[clist[cnt].first][i].first,adj[clist[cnt].first][i].second+clist[cnt].second});
				dist.push_back(adj[clist[cnt].first][i].second+clist[cnt].second);
			}
		}
		cnt++;
	};
	cnt=0;
	for(int i=0;i<n;i++){
		check[i]=0;
	}
	clist.clear();
	clist.push_back({y,0});
	dist.push_back(0);
	check[y]=1;
	while(cnt<clist.size()){
		for(int i=0;i<adj[clist[cnt].first].size();i++){
			if(check[adj[clist[cnt].first][i].first]==0){
				check[adj[clist[cnt].first][i].first]=1;
				clist.push_back({adj[clist[cnt].first][i].first,adj[clist[cnt].first][i].second+clist[cnt].second});
				dist.push_back(adj[clist[cnt].first][i].second+clist[cnt].second);
			}
		}
		cnt++;
	}
	sort(dist.begin(),dist.end());
	long long tdist=0;
	int ans=0;
	for(int i=0;i<dist.size();i++){
		tdist+=dist[i];
		if(tdist>k||i+1==dist.size()){
			ans=i;
			break;
		}
	}
	return ans;
}
/*
4
0 3 20
0 1 18
1 2 1
2 3 19
*/

Compilation message

closing.cpp: In function 'int max_score(int, int, int, long long int, std::vector<int>, std::vector<int>, std::vector<int>)':
closing.cpp:34:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |  while(cnt<clist.size()){
      |        ~~~^~~~~~~~~~~~~
closing.cpp:35:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |   for(int i=0;i<adj[clist[cnt].first].size();i++){
      |               ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
closing.cpp:52:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |  while(cnt<clist.size()){
      |        ~~~^~~~~~~~~~~~~
closing.cpp:53:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |   for(int i=0;i<adj[clist[cnt].first].size();i++){
      |               ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
closing.cpp:65:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |  for(int i=0;i<dist.size();i++){
      |              ~^~~~~~~~~~~~
closing.cpp:67:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |   if(tdist>k||i+1==dist.size()){
      |               ~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 980 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 124 ms 31212 KB Output is correct
2 Correct 140 ms 31432 KB Output is correct
3 Correct 78 ms 3592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Incorrect 1 ms 980 KB 1st lines differ - on the 1st token, expected: '30', found: '24'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Incorrect 1 ms 980 KB 1st lines differ - on the 1st token, expected: '30', found: '24'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Incorrect 1 ms 980 KB 1st lines differ - on the 1st token, expected: '30', found: '24'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 980 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 980 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 980 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 980 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 980 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -