QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#404001 | #6561. Fail Fast | kevinyang | WA | 3ms | 8504kb | C++17 | 1.8kb | 2024-05-03 04:14:04 | 2024-05-03 04:14:05 |
Judging History
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];
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: 8504kb
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: 3ms
memory: 8404kb
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