QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#488225#6342. Security GuardUnforgettablepl0 88ms54052kbC++202.9kb2024-07-23 18:35:172024-07-23 18:35:18

Judging History

你现在查看的是最新测评结果

  • [2024-07-23 18:35:18]
  • 评测
  • 测评结果:0
  • 用时:88ms
  • 内存:54052kb
  • [2024-07-23 18:35:17]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define int long long

struct UFDSsimple{
	vector<int> p,siz,mini;
	UFDSsimple(int n):p(n+1),siz(n+1,1){iota(p.begin(),p.end(),0);}
	int findRoot(int x){
		return p[x]==x ? x : p[x]=findRoot(p[x]);
	}
	bool unite(int a,int b){
		a = findRoot(a);
		b = findRoot(b);
		if(a==b)return false;
		if(siz[b]>siz[a])swap(a,b);
		siz[a]+=siz[b];
		p[b]=a;
		return true;
	}
};

struct UFDS{
	vector<int> p,siz,mini,lazy,decomissioner;
	vector<priority_queue<pair<int,int>>> pq;
	priority_queue<pair<int,int>> globalpq;
	UFDS(int n,vector<int> arr,vector<pair<int,int>> edges):p(n+1),siz(n+1,1),mini(n+1),lazy(n+1),decomissioner(n+1),pq(n+1){
		iota(p.begin(),p.end(),0);
		mini=arr;
		int globalmini = *min_element(arr.begin()+1,arr.end());
		for(int i=0;i<n-1;i++){
			auto [u,v] = edges[i];
			pq[u].emplace(globalmini-arr[v],v);
			pq[v].emplace(globalmini-arr[u],u);
		}
		for(int i=1;i<=n;i++)globalpq.emplace(pq[i].top().first,i);
	}
	int findRoot(int x){
		return p[x]==x ? x : p[x]=findRoot(p[x]);
	}
	void unite(int a,int b){
		a = findRoot(a);
		b = findRoot(b);
		if(a==b)assert(false);
		if(siz[b]>siz[a])swap(a,b);
		int newmin = min(mini[a],mini[b]);
		decomissioner[a]++;
		decomissioner[b]++;
		lazy[a]+=newmin-mini[a];
		lazy[b]+=newmin-mini[b];
		if(pq[b].size()>pq[a].size()){
			swap(pq[a],pq[b]);
			swap(lazy[a],lazy[b]);
		}
		while(!pq[b].empty()){
			auto [cost,v] = pq[b].top();pq[b].pop();
			pq[a].emplace(cost+lazy[b]-lazy[a],v);
		}
		if(!pq[a].empty())globalpq.emplace(pq[a].top().first+lazy[a],a);
		mini[a]=newmin;
		siz[a]+=siz[b];
		p[b]=a;
	}
	int get_best(){
		if(globalpq.empty())assert(false);
		auto [cost,curra] = globalpq.top();globalpq.pop();
		if(decomissioner[curra]){
			decomissioner[curra]--;
			return get_best();
		}
		auto [temp,currb] = pq[curra].top();pq[curra].pop();
		decomissioner[curra]--;
		curra = findRoot(curra);
		currb = findRoot(currb);
		if(curra==currb)return get_best();
		unite(curra,currb);
		return cost;
	}
};


int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	int n,m,q;
	cin >> n >> m >> q;
	vector<int> arr(n+1);
	for(int i=1;i<=n;i++)cin>>arr[i];
	vector<tuple<int,int,int>> edges;
	for(int i=1;i<=m;i++){
		int a,b;
		cin >> a >> b;
		edges.emplace_back(arr[a]+arr[b],a,b);
	}
	sort(edges.begin(),edges.end());
	int baseans = (*max_element(arr.begin(),arr.end()));
	baseans += (n-2ll)*(*min_element(arr.begin()+1,arr.end()));
	UFDSsimple dsusim(n);
	vector<pair<int,int>> gudedges;
	for(int i=0;i<m;i++){
		auto [cost,a,b] = edges[i];
		if(!dsusim.unite(a,b))continue;
		gudedges.emplace_back(a,b);
	}
	vector<int> ans(n);
	ans[0] = baseans;
	UFDS dsu(n,arr,gudedges);
	for(int i=1;i<n;i++){
		ans[i]=ans[i-1]-dsu.get_best();
	}
	for(int i=0;i<=q;i++){
		cout << ans[max(n-1-i,0ll)] << '\n';
	}
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Runtime Error

Test #1:

score: 12
Accepted
time: 88ms
memory: 52708kb

input:

200000 199999 0
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

output:

199999

result:

ok 1 number(s): "199999"

Test #2:

score: 12
Accepted
time: 83ms
memory: 54052kb

input:

200000 199999 0
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ...

output:

399998

result:

ok 1 number(s): "399998"

Test #3:

score: 0
Runtime Error

input:

200000 199999 0
1 2 1 1 1 2 2 1 2 1 1 2 2 2 2 1 1 2 1 1 1 1 2 2 2 1 1 2 2 1 1 1 2 1 1 2 1 1 1 1 1 1 1 2 1 2 2 1 2 1 1 2 1 2 2 2 2 1 2 2 1 2 1 2 2 2 1 1 1 2 1 1 1 2 2 1 1 1 2 2 2 2 1 1 2 2 1 1 2 1 2 1 2 1 2 1 2 1 1 2 1 2 1 2 1 2 1 1 2 1 1 1 2 2 2 1 2 1 1 1 2 1 2 2 2 1 2 1 1 1 1 2 2 1 1 2 1 2 1 2 1 2 ...

output:


result:


Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Skipped

Dependency #3:

0%

Subtask #5:

score: 0
Runtime Error

Test #85:

score: 8
Accepted
time: 6ms
memory: 3624kb

input:

16 15 200000
692461146 622302385 805066691 422290641 600839873 940930580 873147413 489653843 239129952 383473127 21389393 913787109 856138328 859082963 262475462 327598064
6 13
6 9
6 15
6 14
6 16
6 8
5 6
1 6
4 6
3 6
6 11
6 7
6 10
2 6
6 12

output:

14113958700
13194417513
12274876326
11355335139
10435793952
9516252765
8596711578
7677170391
6757629204
5838088017
4918546830
3999005643
3079464456
2159923269
1240382082
1240382082
1240382082
1240382082
1240382082
1240382082
1240382082
1240382082
1240382082
1240382082
1240382082
1240382082
124038208...

result:

ok 200001 numbers

Test #86:

score: 0
Runtime Error

input:

16 30 200000
598416543 514756774 234373059 730937929 122327909 710993525 792876211 799558122 542631332 104191856 970044163 3056707 549900459 673639701 722811840 543231107
3 8
1 11
11 15
6 11
8 9
11 16
3 9
11 14
1 14
4 10
5 13
2 7
6 14
6 16
8 11
4 7
9 11
1 12
7 11
2 8
4 11
10 15
7 15
7 9
4 13
4 8
8 1...

output:


result:


Subtask #6:

score: 0
Skipped

Dependency #5:

0%

Subtask #7:

score: 0
Skipped

Dependency #1:

0%