QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#404004#6561. Fail FastkevinyangWA 0ms8264kbC++171.7kb2024-05-03 04:49:132024-05-03 04:49:14

Judging History

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

  • [2024-05-03 04:49:14]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:8264kb
  • [2024-05-03 04:49:13]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
struct DisjointSet{
	vector<int>parent,sz;
	int size;
	void init(int n){
		size = n;
		parent.resize(n+1); sz.resize(n+1);
		for(int i = 1; i<=n; i++){
			parent[i] = i;
			sz[i] = 1;
		}
	}
	int find(int x){
		if(parent[x]==x)return x;
		return parent[x]=find(parent[x]);
	}
	void Union(int x, int y){
		x = find(x); y = find(y);
		if(x==y)return;
			parent[x] = y;
			sz[y]+=sz[x];
	}
};
const int mxn = 100005;
vector<vector<int>>adj(mxn);
vector<int>parent(mxn);
vector<vector<int>>g(mxn);
struct node{
	double a;
	double b;
};
bool operator <(node a, node b){
	return a.a*a.b + (1-a.b)*b.b*(b.a+a.a) < b.a*b.b + (1-b.b)*a.b*(a.a+b.a);
}
bool operator ==(node a, node b){
	return a.a*a.b + (1-a.b)*b.b*(b.a+a.a) == b.a*b.b + (1-b.b)*a.b*(a.a+b.a);
}
signed main(){
	cin.tie(nullptr)->sync_with_stdio(false);
	int n;
	cin >> n;
	set<pair<node,int>>s;
	vector<node>val(n+1);
	for(int i = 1; i<=n; i++){
		double u, d;
		cin >> u >> d >> parent[i];
		d = 1-d;
		val[i] = node{u,d};
		g[parent[i]].push_back(i);
	}

	vector<pair<node,int>>vals;
	for(int i = 1; i<=n; i++){
		vals.push_back({val[i],i});
	}
	sort(vals.begin(),vals.end());
	vector<int>order(n+1);
	for(int i = 0; i<n; i++){
		order[vals[i].second] = i;
	}
	for(int i = 1; i<=n; i++){
		cout << order[i] << ' ';
	}
	cout << '\n';
	priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>pq;
	pq.push({0,0});
	while(pq.size()){
		auto [_,cur] = pq.top(); pq.pop();
		if(cur!=0)cout << cur << '\n';
		for(int nxt: g[cur]){
			pq.push({order[nxt],nxt});
		}
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 8264kb

input:

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

output:

2 3 0 1 
4
1
2
3

result:

wrong answer Integer 0 violates the range [1, 4]