QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#404006#6561. Fail FastkevinyangWA 3ms8456kbC++171.8kb2024-05-03 04:50:572024-05-03 04:50:58

Judging History

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

  • [2024-05-03 04:50:58]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:8456kb
  • [2024-05-03 04:50:57]
  • 提交

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<pair<int,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);
}
node merge(node a, node b){
	double p = 1-(1-a.b)*(1-b.b);
	return node{1/p*a.a*a.b + 1/p*(1-a.b)*b.b*(b.a+a.a), 1-(1-a.b)*(1-b.b)};
}
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};
	}
	for(int i = 1; i<=n; i++){
		s.insert({val[i],i});
	}
	DisjointSet ds;
	ds.init(n+1);
	for(int i = 1; i<=n; i++){
		auto [res, u] = *s.begin();
		s.erase(s.begin());
		int p = ds.find(parent[u]);
		if(p!=0){
			s.erase({val[p],p});
		}
		val[p] = merge(val[p],res);
		if(p!=0){
			s.insert({val[p],p});
		}
		ds.Union(u,p);
		g[parent[u]].push_back({i,u});
	}
	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(auto nxt: g[cur]){
			pq.push(nxt);
		}
	}
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 3ms
memory: 8344kb

input:

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

output:

4
1
2
3

result:

ok correct

Test #2:

score: 0
Accepted
time: 0ms
memory: 8456kb

input:

4
84 0.716 0
91 0.115 0
19 0.640 1
103 0.455 0

output:

2
1
3
4

result:

ok correct

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 8436kb

input:

10
18 0.574073 0
13 0.540309 0
13 0.539018 2
12 0.572910 2
15 0.570616 4
16 0.510215 3
17 0.504083 5
19 0.539297 1
19 0.577271 7
10 0.578346 1

output:

2
4
3
1
10
6
5
7
8
9

result:

wrong answer your plan is not optimal