QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#132498#6561. Fail FastSorting#RE 0ms0kbC++1.3kb2023-07-30 01:12:512023-07-30 01:12:52

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-30 01:12:52]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2023-07-30 01:12:51]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define fi first
#define se second
int n;
ld len[100001],pass[100001];
int boss[100001];
int par[100001];
int find(int x){
	if(par[x]!=x) par[x]=find(par[x]);
}

int rnk[100001];
vector<int>ch[100001];
int ans[100005];
int main(){
	ios::sync_with_stdio(false);cin.tie(0);
	cin >> n;
	pass[0]=1;
	for(int i=1; i<=n ;i++){
		/*double x;
		int cur;
		scanf("%d%f%d",&cur,&x,&boss[i]);
		pass[i]=x;
		par[i]=i;
		len[i]=cur;*/
		cin >> len[i] >> pass[i] >> boss[i];
		ch[boss[i]].push_back(i);
	}
	auto cmp = [](int a, int b) { return len[a]+pass[a]*len[b]<len[b]+pass[b]*len[a];};
	set<int, decltype(cmp)> s(cmp);
	for(int i=1; i<=n ;i++) s.insert(i);
	for(int i=1; i<=n ;i++){
		int x=*s.begin();s.erase(s.begin());
		rnk[x]=i;
		int y=find(boss[x]);
		if(y!=0) s.erase(y);
		len[y]=len[y]+pass[y]*len[x];
		pass[y]=pass[y]*pass[x];
		par[x]=y;
		if(y!=0) s.insert(y);
	}
	typedef pair<int,int> pii;
	priority_queue<pii,vector<pii>,greater<pii> >pq;
	int ptr=0;
	for(auto c:ch[0]) pq.push({rnk[c],c});
	while(!pq.empty()){
		auto tmp=pq.top();pq.pop();
		ans[++ptr]=tmp.se;
		for(auto c:ch[tmp.se]) pq.push({rnk[c],c});
	}
	for(int i=1; i<=n ;i++) cout << ans[i] << '\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

4
100 0.5 0
200 0.1 1
10 0.5 2
10 0.9 0

output:


result: