Submission #1068192

# Submission time Handle Problem Language Result Execution time Memory
1068192 2024-08-21T08:24:50 Z jamjanek Closing Time (IOI23_closing) C++17
9 / 100
1000 ms 30916 KB
#include "closing.h"
#include <bits/stdc++.h>
using namespace std;

bool odw[200010],odw2[200010];
long long dist[200010];
vector<pair<int,long long>>graf[200010];
long long odl[200010], odl2[200010];
void dfs(int x, int o){
	for(auto j: graf[x])
		if(j.first!=o){
			odl[j.first]=odl[x]+j.second;
			dfs(j.first, x);
		}
}
void dfs2(int x, int o){
	for(auto j: graf[x])
		if(j.first!=o){
			odl2[j.first]=odl2[x]+j.second;
			dfs2(j.first, x);
		}
}
int max_score(int n, int x, int y, long long K,vector<int> U, vector<int> V, vector<int> W)
{
	int i;
	priority_queue<pair<long long,int>>kolejka,kolejka2;
	for(i=0;i<n;i++){
		graf[i].clear();
	}
	for(i=0;i<n-1;i++){
		graf[U[i]].push_back({V[i], W[i]});
		graf[V[i]].push_back({U[i], W[i]});
	}
	odl[y]  = 0;
	odl2[x] = 0;
	dfs(y, -1);
	dfs2(x, -1);
	int wynik = 0;
	for(int ile_x=0;ile_x<n;ile_x++){
		long long k=K;
		for(i=0;i<n;i++)odw[i]=odw2[i]=0,dist[i]=0;
		while(kolejka.size())kolejka.pop();
		while(kolejka2.size())kolejka2.pop();
		kolejka.push({0,x});
		int wyn=0;

		while(kolejka.size()){
			if(wyn==ile_x)break;
			auto a = kolejka.top();
			kolejka.pop();
			if(odw[a.second])continue;
			if(-a.first>k)break;
			dist[a.second]=-a.first;
			odw[a.second]=1;
			k+=a.first;
			wyn++;
			for(auto j: graf[a.second])
				if(odw[j.first]==0)
					kolejka.push({-odl2[j.first], j.first});
		}
		kolejka2.push({0,y});
		while(kolejka2.size()){
			auto a = kolejka2.top();
			kolejka2.pop();
			
			if(-a.first>k)break;
			dist[a.second]+=-a.first;
			odw2[a.second]=1;
			k+=a.first;
			wyn++;
			for(auto j: graf[a.second])
				if(odw2[j.first]==0)
					kolejka2.push({-max(0ll, odl[j.first]-dist[j.first]), j.first});
		}
		
		while(kolejka.size()){
			auto a = kolejka.top();
			kolejka.pop();
			if(odl2[a.second]<=dist[a.second]){
				odw[a.second]=1;
				wyn++;
				for(auto j: graf[a.second])
					if(!odw[j.first])
						kolejka.push({0,j.first});
			}
		}
//		printf("%d %d\n", ile_x, wyn);
//		for(i=0;i<n;i++)printf("%d ", odw[i]);printf("\n");
//		for(i=0;i<n;i++)printf("%d ", odw2[i]);printf("\n");
		wynik  = max(wyn,wynik);
	}
	return wynik;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1042 ms 30916 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5976 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 2 ms 4952 KB Output is correct
4 Correct 3 ms 4956 KB Output is correct
5 Correct 3 ms 4956 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 3 ms 4956 KB Output is correct
8 Correct 2 ms 4956 KB Output is correct
9 Correct 2 ms 4956 KB Output is correct
10 Correct 3 ms 4956 KB Output is correct
11 Correct 2 ms 4956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5976 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 2 ms 4952 KB Output is correct
4 Correct 3 ms 4956 KB Output is correct
5 Correct 3 ms 4956 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 3 ms 4956 KB Output is correct
8 Correct 2 ms 4956 KB Output is correct
9 Correct 2 ms 4956 KB Output is correct
10 Correct 3 ms 4956 KB Output is correct
11 Correct 2 ms 4956 KB Output is correct
12 Correct 3 ms 4956 KB Output is correct
13 Correct 2 ms 4956 KB Output is correct
14 Correct 2 ms 4956 KB Output is correct
15 Correct 2 ms 5980 KB Output is correct
16 Correct 3 ms 5976 KB Output is correct
17 Correct 3 ms 5208 KB Output is correct
18 Incorrect 3 ms 4956 KB 2nd lines differ - on the 1st token, expected: '25', found: '24'
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5976 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 2 ms 4952 KB Output is correct
4 Correct 3 ms 4956 KB Output is correct
5 Correct 3 ms 4956 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 3 ms 4956 KB Output is correct
8 Correct 2 ms 4956 KB Output is correct
9 Correct 2 ms 4956 KB Output is correct
10 Correct 3 ms 4956 KB Output is correct
11 Correct 2 ms 4956 KB Output is correct
12 Correct 3 ms 4956 KB Output is correct
13 Correct 2 ms 4956 KB Output is correct
14 Correct 2 ms 4956 KB Output is correct
15 Correct 2 ms 5980 KB Output is correct
16 Correct 3 ms 5976 KB Output is correct
17 Correct 3 ms 5208 KB Output is correct
18 Incorrect 3 ms 4956 KB 2nd lines differ - on the 1st token, expected: '25', found: '24'
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 3 ms 5976 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 2 ms 4952 KB Output is correct
5 Correct 3 ms 4956 KB Output is correct
6 Correct 3 ms 4956 KB Output is correct
7 Correct 3 ms 4952 KB Output is correct
8 Correct 3 ms 4956 KB Output is correct
9 Correct 2 ms 4956 KB Output is correct
10 Incorrect 2 ms 5156 KB 1st lines differ - on the 1st token, expected: '14', found: '13'
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 3 ms 5976 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 2 ms 4952 KB Output is correct
5 Correct 3 ms 4956 KB Output is correct
6 Correct 3 ms 4956 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 3 ms 4956 KB Output is correct
9 Correct 2 ms 4956 KB Output is correct
10 Correct 2 ms 4956 KB Output is correct
11 Correct 3 ms 4956 KB Output is correct
12 Correct 2 ms 4956 KB Output is correct
13 Correct 3 ms 4956 KB Output is correct
14 Correct 2 ms 4956 KB Output is correct
15 Correct 2 ms 4956 KB Output is correct
16 Correct 2 ms 5980 KB Output is correct
17 Correct 3 ms 5976 KB Output is correct
18 Correct 3 ms 5208 KB Output is correct
19 Correct 3 ms 4952 KB Output is correct
20 Correct 3 ms 4956 KB Output is correct
21 Correct 2 ms 4956 KB Output is correct
22 Incorrect 2 ms 5156 KB 1st lines differ - on the 1st token, expected: '14', found: '13'
23 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 3 ms 5976 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 2 ms 4952 KB Output is correct
5 Correct 3 ms 4956 KB Output is correct
6 Correct 3 ms 4956 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 3 ms 4956 KB Output is correct
9 Correct 2 ms 4956 KB Output is correct
10 Correct 2 ms 4956 KB Output is correct
11 Correct 3 ms 4956 KB Output is correct
12 Correct 2 ms 4956 KB Output is correct
13 Correct 3 ms 4956 KB Output is correct
14 Correct 2 ms 4956 KB Output is correct
15 Correct 2 ms 4956 KB Output is correct
16 Correct 2 ms 5980 KB Output is correct
17 Correct 3 ms 5976 KB Output is correct
18 Correct 3 ms 5208 KB Output is correct
19 Incorrect 3 ms 4956 KB 2nd lines differ - on the 1st token, expected: '25', found: '24'
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 3 ms 5976 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 2 ms 4952 KB Output is correct
5 Correct 3 ms 4956 KB Output is correct
6 Correct 3 ms 4956 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 3 ms 4956 KB Output is correct
9 Correct 2 ms 4956 KB Output is correct
10 Correct 2 ms 4956 KB Output is correct
11 Correct 3 ms 4956 KB Output is correct
12 Correct 2 ms 4956 KB Output is correct
13 Correct 3 ms 4956 KB Output is correct
14 Correct 2 ms 4956 KB Output is correct
15 Correct 2 ms 4956 KB Output is correct
16 Correct 2 ms 5980 KB Output is correct
17 Correct 3 ms 5976 KB Output is correct
18 Correct 3 ms 5208 KB Output is correct
19 Incorrect 3 ms 4956 KB 2nd lines differ - on the 1st token, expected: '25', found: '24'
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 3 ms 5976 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 2 ms 4952 KB Output is correct
5 Correct 3 ms 4956 KB Output is correct
6 Correct 3 ms 4956 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 3 ms 4956 KB Output is correct
9 Correct 2 ms 4956 KB Output is correct
10 Correct 2 ms 4956 KB Output is correct
11 Correct 3 ms 4956 KB Output is correct
12 Correct 2 ms 4956 KB Output is correct
13 Correct 3 ms 4956 KB Output is correct
14 Correct 2 ms 4956 KB Output is correct
15 Correct 2 ms 4956 KB Output is correct
16 Correct 2 ms 5980 KB Output is correct
17 Correct 3 ms 5976 KB Output is correct
18 Correct 3 ms 5208 KB Output is correct
19 Incorrect 3 ms 4956 KB 2nd lines differ - on the 1st token, expected: '25', found: '24'
20 Halted 0 ms 0 KB -