QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#403999#6561. Fail FastkevinyangWA 2ms8616kbC++171.8kb2024-05-03 04:08:532024-05-03 04:08:54

Judging History

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

  • [2024-05-03 04:08:54]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:8616kb
  • [2024-05-03 04:08:53]
  • 提交

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){
	return node{a.a*a.b + (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];
		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: 2ms
memory: 8544kb

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: -100
Wrong Answer
time: 2ms
memory: 8616kb

input:

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

output:

1
3
4
2

result:

wrong answer your plan is not optimal