QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#609500 | #6561. Fail Fast | Forever_Young | WA | 1ms | 8032kb | C++23 | 1.2kb | 2024-10-04 13:16:17 | 2024-10-04 13:16:18 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define data dataa
using LL=long long;
using ULL=unsigned long long;
using LD=long double;
const int N=int(1e5)+10;
priority_queue<pair<double,int>,vector<pair<double,int>>,greater<pair<double,int>>>q;
priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>Q;
vector<int>g[N];
double c[N<<1],p[N<<1];
int par[N],fa[N<<1],id[N<<1],n,t[N];
int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
int main()
{
scanf("%d",&n);
rep(i,n)scanf("%lf%lf%d",&c[i],&p[i],&par[i]),q.push(mp(c[i]/(1-p[i]),i)),fa[i]=i,id[i]=i,g[par[i]].pb(i);
rep(i,n)
{
int x=q.top().second;q.pop();
for(;fa[x]!=x;x=q.top().second,q.pop());
t[id[x]]=i;
if(!par[id[x]])continue;
int fx=n+i,y=find(par[id[x]]);
fa[fx]=fx;id[fx]=id[y];
fa[x]=fx;fa[y]=fx;
p[fx]=p[y]*p[x],c[fx]=c[y]+p[y]*c[x];
q.push(mp(c[fx]/(1-p[fx]),fx));
}
for(auto x:g[0])Q.push(mp(t[x],x));
rep(i,n)
{
int x=Q.top().second;Q.pop();
printf("%d\n",x);
for(auto y:g[x])Q.push(mp(t[y],y));
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 8032kb
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: 1ms
memory: 7900kb
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: 7996kb
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 6 5 7 9 1 8 10
result:
wrong answer your plan is not optimal