Submission #878487

# Submission time Handle Problem Language Result Execution time Memory
878487 2023-11-24T14:15:47 Z Sandro123 Closing Time (IOI23_closing) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#pragma GCC diagnostic warning "-std=c++11"
#define pb push_back
#define int long long
#define f first
#define s second
using namespace std;
const int P=2*1e6+5;
vector <pair <int,int> > gr[P];
int fix[P],dist[2*P];
int d,nd;
void dfs(int x){
	fix[x]=1;
	for(int i=0; i<gr[x].size(); i++){
		int v=gr[x][i].f;
		if(fix[v]==0){
			nd++; d+=gr[x][i].s; dist[nd]+=gr[x][i].s; dfs(v); d-=gr[x][i].s;
		}
	}
}
int max_score(int N, int X, int Y, long long K, std::vector<int> U, std::vector<int> V, std::vector<int> W){
    for(int i=0; i<N; i++){
    	fix[i]=0; gr[i].clear();
	}
	for(int i=0; i<2*N; i++){
		dist[i]=0;
	}
	for(int i=0; i<N; i++){
		gr[U[i]].pb({V[i],W[i]});
		gr[V[i]].pb({U[i],W[i]});
	}
	d=0; nd=0; dist[0]=0;
	dfs(X);
	for(int i=0; i<N; i++){
		fix[i]=0;
	}
	nd++; d=0; dist[nd]=0; dfs(Y);
	sort(dist,dist+nd+1);
	int sm=0,ans=0;
	for(int i=0; i<2*N; i++){
		if(sm+dist[i]>K){
			break;
		}
		sm+=dist[i];
		ans++;
	}
	return ans;
}
main(){
	ios_base::sync_with_stdio(false);
    int T = 1;
    cin >> T;
    while(T--){
        cout<<max_score()<<endl;
    }
}

Compilation message

closing.cpp:2:32: warning: '-std=c++11' is not an option that controls warnings [-Wpragmas]
    2 | #pragma GCC diagnostic warning "-std=c++11"
      |                                ^~~~~~~~~~~~
closing.cpp: In function 'void dfs(long long int)':
closing.cpp:14:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |  for(int i=0; i<gr[x].size(); i++){
      |               ~^~~~~~~~~~~~~
closing.cpp: At global scope:
closing.cpp:49:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   49 | main(){
      | ^~~~
closing.cpp: In function 'int main()':
closing.cpp:54:25: error: too few arguments to function 'long long int max_score(long long int, long long int, long long int, long long int, std::vector<long long int>, std::vector<long long int>, std::vector<long long int>)'
   54 |         cout<<max_score()<<endl;
      |                         ^
closing.cpp:21:5: note: declared here
   21 | int max_score(int N, int X, int Y, long long K, std::vector<int> U, std::vector<int> V, std::vector<int> W){
      |     ^~~~~~~~~