QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#404005 | #6561. Fail Fast | kevinyang | WA | 3ms | 8496kb | C++17 | 1.6kb | 2024-05-03 04:49:33 | 2024-05-03 04:49:33 |
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<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;
}
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: 100
Accepted
time: 0ms
memory: 8364kb
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: 8496kb
input:
4 84 0.716 0 91 0.115 0 19 0.640 1 103 0.455 0
output:
2 4 1 3
result:
wrong answer your plan is not optimal