Problem:
夏合宿の朝は早い
JAG夏合宿の朝は早い．
正確にはそこまで早くないが，早いと感じる参加者が多いという．
例年合宿の会場となる施設では，退去時に参加者がシーツの回収や掃除をしなければならない．
1 つの部屋でも退去が遅れると，来年以降の施設の利用に関わるため，参加者は一人たりとも寝坊してはならない．
そうは言っても皆人間，寝坊することもある．
しかし，起きた人が連絡先を知っている人にモーニングコールをすることで，一人も寝坊しないよう努めることができるはずだ．
JAG夏合宿の運営を任されたあなたは，寝坊を絶対に防ぐ手を打つための前準備として，どのくらいの確率で全員がきちんと起きられるのかを調べることにした．
準備としてまず，各参加者の寝坊する確率と，各々が連絡先を知っている人のリストを入手した．
ここで，部屋は個室であるため，各々が寝坊するか否かは，他の参加者が寝坊するか否かとは独立である．
起きた人は必ずすべての知っている連絡先にモーニングコールをすること，また，モーニングコールを受けた人は必ず起きることを仮定するとき，全員がきちんと起きられる確率をこれらの情報から計算せよ．
Input
入力は複数のデータセットからなる． 各データセットは次の形式で表される．
N
p
1
m
1
a
(1,1)
...
a
(1, m
1
)
...
p
N
m
N
a
(N,1)
...
a
(N, m
N
)
N
は参加者の数であり，100 を越えない正の整数である．
p
i
は
i
番目の参加者の寝坊する確率であり，小数点以下 2 桁以内の 0 以上 1 以下の実数である．
m
i
は
i
番目の参加者が知っている連絡先の数であり，0 以上
N
以下の整数である．
a
(i, j)
は
i
番目の参加者が知っている
j
番目の連絡先が
a
(i, j)
番目の参加者のものであることを表す．
a
(i, j)
は
N
を越えない正の整数である．
入力の終わりは，1 つのゼロからなる行で示す．
Output
各データセットについて，全員が起床できる確率を 1 行に出力せよ．出力には 0.00001 以上の誤差を含んではならない．
Sample Input
2
0.60 1 2
0.60 0
2
0.60 1 2
0.60 1 1
5
0.10 1 2
0.20 1 3
0.30 1 4
0.40 1 5
0.50 1 1
5
0.10 0
0.20 1 1
0.30 1 1
0.40 1 1
0.50 1 1
5
0.10 4 2 3 4 5
0.20 0
0.30 0
0.40 0
0.50 0
4
0.10 1 2
0.20 0
0.30 1 4
0.40 1 3
5
0.10 0
0.20 0
0.30 0
0.40 0
0.50 0
0
Output for Sample Input
0.400000000
0.640000000
0.998800000
0.168000000
0.900000000
0.792000000
0.151200000

Submitted solutions:

code_snippet: #pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

// #ifndef ONLINE_JUDGE
// #define _GLIBCXX_DEBUG // 配列外参照のエラー
// #endif

// スタンダードライブラリ
#include <bits/stdc++.h>
using namespace std;

// 型関連
using ll = long long;
using lint = long long;
using pll = pair<ll, ll>;
using plll = tuple<ll, ll, ll>;
using pii = pair<int, int>;
using piii = tuple<ll, ll, ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vvvvi = vector<vector<vector<vector<int>>>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
using vvvvl = vector<vector<vector<vector<ll>>>>;

template <class T> using prique = priority_queue<T>;

// 型定数
constexpr ll mod = 998244353;
constexpr ll MOD = 1000000007;
int INF32 = 1e9;
ll INF64 = 9e18;
#define endl '\n';

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

/////////////////////////// print関連
template <typename T> void print(vector<T> A);
void print();
template <class Head, class... Tail> void print(Head &&head, Tail &&...tail);
void print(string S);
template <typename T> void print(vector<vector<T>> &F);

inline void Yes(bool f);

///////////////////ここから//////////////////////
bool solve() {

    int N;
    cin >> N;
    if (N == 0) {
        return false;
    }
    vector<double> P(N);
    vector<vector<int>> E(N, vector<int>(N, INF32));
    for (int i = 0; i < N; i++) {
        double p;
        cin >> p;
        P[i] = p;
        int m;
        cin >> m;
        for (int j = 0; j < m; j++) {
            int v;
            cin >> v;
            v--;
            E[i][v] = 1;
        }
    }
    for (int k = 0; k < N; k++) {
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                E[i][j]=min(E[i][j],E[i][k]+E[k][j]);
            }
        }
    }
    
    vector<vector<int>> G(N);
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            if (E[i][j] != INF32 && E[j][i] != INF32) {
                G[i].push_back(j);
                G[j].push_back(i);
            }
        }
    }

    vector<int> dist(N, -1);
    vector<vector<int>> c2v;
    unordered_set<int> se;
    auto bfs = [&](int sv, int color) {
        queue<int> que;
        vector<int> lis;
        que.emplace(sv);
        dist[sv]=color;
        se.insert(color);
        while (!que.empty()) {
            int v = que.front();
            lis.push_back(v);
            que.pop();
            for (auto nv : G[v]) {
                if (dist[nv] != -1) {
                    continue;
                }
                dist[nv] = color;
                que.push(nv);
            }
        }
        c2v.push_back(lis);
    };

    int n=0;
    for (int i = 0; i < N; i++) {
        if (dist[i] == -1) {
            bfs(i, n);
            n++;
        }
    }

    
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            if (E[i][j] != INF32 && E[j][i] == INF32) {
                se.erase(dist[j]);
            }
        }
    }

    double ans=1;
    for (auto V : se) {
        
        double neru=1;
        for (auto v : c2v[V]) {
            neru*=P[v];
        }
        ans*=1.0-neru;
    }
    cout<<fixed<<setprecision(10);
    cout<<ans<<endl;
    


    return true;
}

int main() {
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    while (solve())
        ;
}

////////////////////print/////////////////////////
// 1次元ベクトルを出力する
template <typename T> void print(vector<T> A) {
    if (A.size() == 0) {
        return;
    }
    for (size_t i = 0; i < A.size() - 1; i++) {
        cout << A[i] << ' ';
    }
    cout << A[A.size() - 1] << endl;
    return;
}

// 2次元ベクトルを出力する
template <typename T> void print(vector<vector<T>> &F) {
    for (size_t i = 0; i < F.size(); i++) {
        for (size_t j = 0; j < F[i].size(); j++) {
            cout << F[i][j];
            if (j < F[i].size() - 1) {
                cout << ' ';
            }
        }
        cout << endl;
    }
}

// 空白行を出力するprint
void print() { cout << endl; }

// 数値・文字列を空白区切りで出力する. print(a,b)など
template <class Head, class... Tail> void print(Head &&head, Tail &&...tail) {
    cout << head;
    if (sizeof...(tail) != 0)
        cout << " ";
    print(forward<Tail>(tail)...);
}

void print(string S) { cout << S << endl; }

//////////////出力関連

inline void Yes(bool f) {
    if (f) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}
accuracy: 1
time_ms: 10
memory_kb: 3968
final_rank: 18

code_snippet: #include<bits/stdc++.h>
using namespace std;

struct UnionFind {
    vector<int> par, siz;
    UnionFind(int n) : par(n,-1), siz(n,1) {}
    int find(int x){
        if (par[x] == -1) return x;
        else{
            par[x] = find(par[x]);
            return par[x];
        }
    }
    bool same(int x, int y){
        return find(x) == find(y);
    }
    int size(int x){
        return siz[find(x)];
    }
    void merge(int x, int y){
        x = find(x);
        y = find(y);
        if (x == y) return;
        if (siz[x] < siz[y]) swap(x,y);
        siz[x] += siz[y];
        par[y] = x;
    }
};

bool solve(){
    int N;
    cin>>N;
    if(N==0)return false;
    vector<double>P(N);
    vector<vector<int>>G(N);
    for(int i=0;i<N;i++){
        cin>>P[i];
        int m;
        cin>>m;
        for(int j=0;j<m;j++){
            int a;
            cin>>a;
            a--;
            G[i].push_back(a);
        }
    }
    vector flag(N,vector<bool>(N));
    for(int s=0;s<N;s++){
        queue<int>q;
        q.push(s);
        flag[s][s]=true;
        while(q.size()){
            int x=q.front();
            q.pop();
            for(auto i:G[x]){
                if(!flag[s][i]){
                    flag[s][i]=true;
                    q.push(i);
                }
            }
        }
    }
    UnionFind uf(N);
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            if(flag[i][j]&&flag[j][i]){
                uf.merge(i,j);
            }
        }
    }
    vector<bool>flag2(N);
    vector<vector<int>>group(N);
    vector<int>V;
    for(int i=0;i<N;i++){
        int l=uf.find(i);
        group[l].push_back(i);
        if(!flag2[l]){
            flag2[l]=true;
            V.push_back(l);
        }
    }
    vector<int>in(N);
    for(int i=0;i<(int)V.size();i++)for(int j=0;j<(int)V.size();j++){
        if(i==j)continue;
        if(flag[V[i]][V[j]])in[V[j]]++;
        if(flag[V[j]][V[i]])in[V[i]]++;
    }
    double ans=1.0;
    for(int k=0;k<(int)V.size();k++){
        int i=V[k];
        if(in[i]==0){
            double q=1;
            for(auto j:group[i]){
                q*=P[j];
            }
            ans*=1.0-q;
        }
    }
    cout<<ans<<"\n";
    return true;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout<<fixed<<setprecision(12);
    while(1){
        if(!solve()){
            return 0;
        }
    }
}
accuracy: 1
time_ms: 10
memory_kb: 3616
final_rank: 13

code_snippet: #include <bits/stdc++.h>

using namespace std;
using i64 = long long;
using vi = vector<int>;
using vvi = vector<vi>;


bool solve(){
    int n;
    cin >> n;
    if(n == 0){
        return false;
    }
    vector<double> p(n);
    vector<int> m(n);
    vector<vector<int>> edges(n), rev(n);
    for (int i = 0; i < n; ++i) {
        cin >> p[i] >> m[i];
        edges[i].resize(m[i]);
        for (int j = 0; j < m[i]; ++j) {
            cin >> edges[i][j];
            --edges[i][j];
            rev[edges[i][j]].emplace_back(i);
        }
    }
    vector<bitset<100>> bs(n);
    for(int i = 0; i < n; ++i){
        queue<int> que;
        que.emplace(i);
        bitset<100> come;
        come.set(i);
        que.push(i);
        while(!que.empty()){
            int x = que.front();
            que.pop();
            for(auto y : rev[x]){
                if(!come[y]){
                    come[y] = true;
                    que.emplace(y);
                }
            }
        }
        bs[i] = come;
    }
    map<string, vector<int>> component;
    for(int i = 0; i < n; ++i){
        string s = bs[i].to_string();
        component[s].emplace_back(i);
    }
    vector<vector<int>> cons(component.size());
    vector<int> inv(n);
    int idx = 0;
    for(auto [k, v] : component){
        cons[idx] = v;
        for(auto x : v) {
            inv[x] = idx;
        }
        ++idx;
    }
    vector<vector<int>> group_edges(cons.size());
    vector<set<int>> group_edges_rev(cons.size());
    for (int i = 0; i < cons.size(); ++i) {
        for(auto x : cons[i]){
            /*
            for(auto y : edges[x]) {
                group_edges[i].emplace_back(inv[y]);
            }*/
            for(auto y : rev[x]){
                if(inv[y] != i) {
                    group_edges_rev[i].emplace(inv[y]);
                }
            }
        }
    }
    /*
    for (int i = 0; i < cons.size(); ++i) {
        sort(group_edges[i].begin(), group_edges[i].end());
        group_edges[i].erase(unique(group_edges[i].begin(), group_edges[i].end()), group_edges[i].end());
    }
     */

    /*
    for(auto v : cons){
        for(auto x : v){
            cout << x << " ";
        }
        cout << endl;
    }
    cout << endl;
    return true;
     */

    double prob = 1.0;
    for (int i = 0; i < cons.size(); ++i) {
        if(group_edges_rev[i].empty()){
            double p2 = 1.0;
            for (auto x : cons[i]){
                p2 *= p[x];
            }
            prob *= 1.0 - p2;
        }
    }
    printf("%.10lf\n", prob);

    return true;
}

signed main(){
    while(solve());
}
accuracy: 1
time_ms: 10
memory_kb: 3748
final_rank: 14

code_snippet: #include <stdio.h>
#include <vector>
using namespace std;

double prob[128], sprob[128];
int reach[128][128], scc[128], vis[128];
vector<int> ed[128], rsed[128];

int main(void) {
    int n, m, x, scc_cnt;
    double res;
    while (1) {
        scanf("%d", &n);
        if (n == 0) break;
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) reach[i][j] = 0;
            scc[i] = 0;
            ed[i].clear();
            rsed[i].clear();
            vis[i] = 0;
            sprob[i] = 0;
        }
        scc_cnt = 0;
        for (int i = 1; i <= n; i++) {
            scanf("%lf %d", &prob[i], &m);
            prob[i] = 1.0 - prob[i];
            for (int j = 0; j < m; j++) {
                scanf("%d", &x);
                ed[i].push_back(x);
                reach[i][x] = 1;
            }
        }
        for (int k = 1; k <= n; k++) {
            for (int i = 1; i <= n; i++) {
                for (int j = 1; j <= n; j++) reach[i][j] |= (reach[i][k] & reach[k][j]);
            }
        }

        for (int i = 1; i <= n; i++) {
            if (scc[i] > 0) continue;
            scc[i] = ++scc_cnt;
            for (int j = 1; j <= n; j++) {
                if (reach[i][j] && reach[j][i]) scc[j] = scc_cnt;
            }
        }

        for (int i = 1; i <= n; i++) {
            for (int j : ed[i]) {
                if (scc[i] != scc[j]) {
                    rsed[scc[j]].push_back(scc[i]);
                }
            }
        }

        for (int i = 1; i <= scc_cnt; i++) {
            sprob[i] = 1.0;
            for (int j = 1; j <= n; j++) {
                if (scc[j] != i) continue;
                sprob[i] *= (1.0 - prob[j]);
            }
            sprob[i] = 1.0 - sprob[i];
        }

        res = 1.0;
        for (int i = 1; i <= scc_cnt; i++) {
            if (rsed[i].size() == 0) res *= sprob[i];
        }
        printf("%.9f\n", res);
    }
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3088
final_rank: 1

code_snippet: #include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define _GLIBCXX_DEBUG
using namespace std;
using std::cout;
using std::cin;
using std::endl;
using ll=long long;
using ld=long double;
ll ILL=1167167167167167167;
const int INF=2100000000;
const ll mod=1e9+7;
#define rep(i,a) for (int i=0;i<a;i++)
#define all(p) p.begin(),p.end()
template<class T> using _pq = priority_queue<T, vector<T>, greater<T>>;
template<class T> ll LB(vector<T> &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> ll UB(vector<T> &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}else return 0;}
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}else return 0;}
template<class T> void So(vector<T> &v) {sort(v.begin(),v.end());}
template<class T> void Sore(vector<T> &v) {sort(v.begin(),v.end(),[](T x,T y){return x>y;});}
void yneos(bool a){if(a) cout<<"Yes\n"; else cout<<"No\n";}
template<class T> void vec_out(vector<T> &p){for(int i=0;i<(int)(p.size());i++){if(i) cout<<" ";cout<<p[i];}cout<<"\n";}

int N,M;

void solve();
// oddloop
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	while(cin>>N,N) solve();
}

void solve(){
	vector<ld> pro(N);
	vector<vector<int>> G(N);
	rep(i,N){
		cin>>pro[i];
		int k;
		cin>>k;
		rep(j,k){
			int a;
			cin>>a;
			a--;
			G[i].push_back(a);
		}
	}
	vector<vector<bool>> H(N,vector<bool>(N));
	rep(i,N){
		H[i][i]=1;
		vector<int> order={i};
		int ind=0;
		while((int)(order.size())!=ind){
			int a=order[ind];
			for(auto x:G[a]){
				if(!H[i][x]){
					H[i][x]=1;
					order.push_back(x);
				}
			}
			ind++;
		}
	}
	vector<bool> seen(N);
	rep(i,N){
		rep(j,N){
			int J=3;
			rep(k,N){
				if(H[i][k]&!H[j][k]) J&=1;
				if(H[j][k]&!H[i][k]) J&=2;
			}
			if(J==2) seen[i]=1;
		}
	}
	ld ans=1;
	rep(i,N){
		if(seen[i]) continue;
		ld tmp=1;
		rep(j,N){
			if(seen[j]) continue;
			rep(k,N){
				if(H[i][k]^H[j][k]) break;
				if(k==N-1){
					tmp*=pro[j];
					seen[j]=1;
				}
			}
		}
		ans=(ans*(1-tmp));
	}
	cout<<fixed<<setprecision((18))<<ans<<"\n";
}
accuracy: 1
time_ms: 20
memory_kb: 3612
final_rank: 16

code_snippet: #pragma GCC target("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
#define DEBUG
#ifdef DEBUG
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << '(' << p.first << ',' << p.second << ')';
    return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << '{';
    for(int i = 0; i < (int)v.size(); i++) {
        if(i) { os << ','; }
        os << v[i];
    }
    os << '}';
    return os;
}
void debugg() { cerr << endl; }
template <class T, class... Args>
void debugg(const T &x, const Args &... args) {
    cerr << " " << x;
    debugg(args...);
}
#define debug(...)                                                             \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]: ", debugg(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = (1<<30)-1;
const ll linf = 1LL<<61;
const int MAX = 510000;
int dy[8] = {0,1,0,-1,1,-1,-1,1};
int dx[8] = {-1,0,1,0,1,-1,1,-1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    int sz = a.size();
    for(auto itr = a.begin(); itr != a.end(); itr++){
		cout << *itr;
        sz--;
        if(sz) cout << " ";
	}
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){
	cout << a << " " << b << "\n";
}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
void mark() {cout << "#" << "\n";}
ll pcount(ll x) {return __builtin_popcountll(x);}
const int mod = 1e9 + 7;
//const int mod = 998244353;

template< typename G >
struct StronglyConnectedComponents {
  const G &g;
  G gg, rg;
  vector< int > comp, order, used;

  StronglyConnectedComponents(G &g) : g(g), gg(g.size()), rg(g.size()), comp(g.size(), -1), used(g.size()) {
    for(int i = 0; i < g.size(); i++) {
      for(auto e : g[i]) {
        gg[i].emplace_back((int) e);
        rg[(int) e].emplace_back(i);
      }
    }
  }

  int operator[](int k) {
    return comp[k];
  }

  void dfs(int idx) {
    if(used[idx]) return;
    used[idx] = true;
    for(int to : gg[idx]) dfs(to);
    order.push_back(idx);
  }

  void rdfs(int idx, int cnt) {
    if(comp[idx] != -1) return;
    comp[idx] = cnt;
    for(int to : rg[idx]) rdfs(to, cnt);
  }

  int build(G &t) {
    for(int i = 0; i < gg.size(); i++) dfs(i);
    reverse(begin(order), end(order));
    int ptr = 0;
    for(int i : order) if(comp[i] == -1) rdfs(i, ptr), ptr++;

    t.resize(ptr);
    for(int i = 0; i < g.size(); i++) {
      for(auto &to : g[i]) {
        int x = comp[i], y = comp[to];
        if(x == y) continue;
        t[x].push_back(y);
      }
    }
    return ptr;
  }
};

int main(){
    //cin.tie(nullptr);
    //ios::sync_with_stdio(false);
    while(1){
        int n; cin >> n;
        if(!n) break;
        vd p(n);
        vvl g(n), h;
        rep(i,n){
            cin >> p[i];
            int m; cin >> m;
            rep(j,m){
                int a; cin >> a; a--;
                g[i].push_back(a);
            }
        }
        StronglyConnectedComponents<vvl> scc(g);
        int k = scc.build(h);
        vl indeg(k,0);
        rep(i,k){
            sort(all(h[i]));
            h[i].erase(unique(all(h[i])), h[i].end());
            for(auto v : h[i]) indeg[v]++;
        }
        vd P(k,1.0);
        rep(i,n) P[scc[i]] *= p[i];
        rep(i,k) P[i] = 1 - P[i];
        double ans = 1;
        rep(i,k){
            if(indeg[i] == 0) ans *= P[i];
        }
        cout << fixed << setprecision(10) << ans << "\n";
    }
}
accuracy: 1
time_ms: 10
memory_kb: 3400
final_rank: 8

code_snippet: #include <bits/stdc++.h>
using namespace std;

#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()

struct SCC{
  vector<vector<int>> G,R,T,C;
  //G:元のグラフ R:Gの逆辺グラフ T:DAG C[i]:SCC後の頂点iに属しているGの頂点集合
  vector<int> vs,used,blg;
  //blg[v]:元のグラフで頂点vがSCC後に属している頂点の名前
  SCC(){}
  SCC(int n):G(n),R(n),used(n),blg(n){}
  void add_edge(int u,int v){
    G[u].emplace_back(v);
    R[v].emplace_back(u);
  }
  inline void dfs(int v){
    used[v]=1;
    for(int u:G[v])if(!used[u])dfs(u);
    vs.emplace_back(v);
  }
  inline void rdfs(int v,int k){
    used[v]=1;
    blg[v]=k;
    C[k].emplace_back(v);
    for(int u:R[v])if(!used[u])rdfs(u,k);
  }
  int build(){//DAGのサイズを返す
    int n=G.size();
    for(int v=0;v<n;v++)if(!used[v])dfs(v);
    fill(used.begin(),used.end(),0);
    int k=0;
    for(int i=n-1;i>=0;i--)
      if(!used[vs[i]]){
        T.emplace_back();
        C.emplace_back();
        rdfs(vs[i],k++);
      }
    for(int v=0;v<n;v++)
      for(int u:G[v])
        if(blg[v]!=blg[u])
          T[blg[v]].push_back(blg[u]);
    for(int i=0;i<k;i++){
      sort(T[i].begin(),T[i].end());
      T[i].erase(unique(T[i].begin(),T[i].end()),T[i].end());
    }
    return k;
  }
  int operator[](int k) const{return blg[k];}
};
using ld=long double;

signed main(){
  int n;
  while(cin>>n,n){
    SCC g(n);
    vector<ld> p(n);
    REP(i,n){
      cin>>p[i];
      int m;cin>>m;
      while(m--){
        int a;cin>>a;a--;
        g.add_edge(i,a);
      }
    }
    int k=g.build();
    vector<ld> v(k,1);
    REP(i,n)v[g[i]]*=p[i];
    REP(i,n)for(int q:g.G[i])if(g[i]!=g[q])v[g[q]]=0;
    ld ans=1;
    REP(i,k)ans*=1-v[i];
    cout<<fixed<<setprecision(12)<<ans<<endl;
  }
}
accuracy: 1
time_ms: 10
memory_kb: 3428
final_rank: 10

code_snippet: #include <bits/stdc++.h>
using namespace std;

class Scc
{
public:
    int N;
    vector<vector<int>> G, rG;
    vector<int> vs;
    vector<bool> used;
    vector<int> cmp;
    vector<double> p, pp;

    Scc(vector<vector<int>> _G, vector<double> _p) : G(_G), p(_p)
    {
        N = G.size();
        rG.resize(N, vector<int>());
        for (int i = 0; i < G.size(); i++)
        {
            for (auto nv : G[i])
            {
                rG[nv].push_back(i);
            }
        }
        used.resize(N);
        cmp.resize(N);
    }

    void dfs(int v)
    {
        used[v] = true;
        for (auto nv : G[v])
        {
            if (!used[nv])
                dfs(nv);
        }
        vs.push_back(v);
    }

    void rdfs(int v, int k)
    {
        used[v] = true;
        cmp[v] = k;
        for (auto nv : rG[v])
        {
            if (!used[nv])
                rdfs(nv, k);
        }
    }

    int scc()
    {
        fill(used.begin(), used.end(), false);
        for (int v = 0; v < N; v++)
        {
            if (!used[v])
                dfs(v);
        }
        fill(used.begin(), used.end(), false);
        int k = 0;
        for (int i = N - 1; i >= 0; i--)
        {
            if (!used[vs[i]])
                rdfs(vs[i], k++);
        }
        return k;
    }

    double solve()
    {
        int k = scc();
        vector<vector<int>> g(k, vector<int>());
        pp.resize(k, 1.0);
        vector<int> in(k);
        for (int i = 0; i < N; i++)
        {
            pp[cmp[i]] *= p[i];
        }
        for (int i = 0; i < N; i++)
        {
            for (auto nv : G[i])
            {
                if (cmp[i] == cmp[nv])
                    continue;
                g[cmp[i]].push_back(cmp[nv]);
                in[cmp[nv]]++;
            }
        }
        double ret = 1.0;
        for (int i = 0; i < k; i++)
        {
            if (in[i] == 0)
            {
                ret *= (1.0 - pp[i]);
            }
        }

        return ret;
    }
};

int main()
{
    int N;
    while (cin >> N, N)
    {
        vector<double> p(N);
        vector<vector<int>> G(N, vector<int>());
        for (int i = 0; i < N; i++)
        {
            cin >> p[i];
            int m;
            cin >> m;
            for (int j = 0; j < m; j++)
            {
                int d;
                cin >> d;
                d--;
                G[i].push_back(d);
            }
        }
        Scc Scc(G, p);
        cout << fixed << setprecision(10) << Scc.solve() << endl;
    }
}
accuracy: 1
time_ms: 10
memory_kb: 3372
final_rank: 5

code_snippet: #include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;

#define MAX_N 100

int reached[MAX_N][MAX_N]={};


int parent[MAX_N];
int ran[MAX_N];

void init(int n)
{
  int i;
  rep(i,n){
    parent[i]=i;
    ran[i]=0;
  }
}

int find(int x)
{
  if(parent[x]==x)
    return x;
  else
    return parent[x]=find(parent[x]);
}

void unite(int x,int y)
{
  x=find(x);
  y=find(y);
  if(x==y)return;

  if(ran[x]<ran[y])
    parent[x]=y;
  else{
    parent[y]=x;
    if(ran[x]==ran[y])ran[x]++;
  }
}

void dfs(int s, int v, vector<vi> g){
  reached[s][v]++;
  int i;
  rep(i,g[v].size())
    if(reached[s][g[v][i]]==0)dfs(s,g[v][i],g);

}

int main(void) {
  int i,j;
  while(1){
    int n;
    cin>>n;
    if(n==0)break;
    vector<vi> g(n);
    vector<double> p(n);
    rep(i,n){
      cin>>p[i];
      int m;
      cin>>m;
      rep(j,m){
	int a;
	cin>>a;
	a--;
	g[i].push_back(a);	
      }
    }

    rep(i,n)rep(j,n)reached[i][j]=0;

    rep(i,n)dfs(i,i,g); //reached[i][j]を埋める

    init(100);//UF

    rep(i,n)loop(j,i+1,n)
      if(reached[i][j] && reached[j][i])unite(i,j);//UF

    double ans=1;

    int q;
    rep(q,n){
      bool c=true;//qに到達可能なものがない
      double tmp=1;//強連結成分qの全体の確率

      rep(i,n)if(find(parent[i])==q){//iがqに属する場合

	tmp*=p[i];

	//jがiと異なる強連結成分に属し、jがiに到達可能の場合
	rep(j,n)if(find(parent[i])!=find(parent[j]) && reached[j][i]){
	  c=false;
	}

      }

      if(c && fabs(tmp-1)>EPS) ans*=1-tmp;
  
    }

    cout<<shosu(10)<<ans<<endl;

  }
}
accuracy: 1
time_ms: 780
memory_kb: 7540
final_rank: 20

code_snippet: #include <bits/stdc++.h>
using namespace std;

#include <algorithm>

#include <algorithm>
#include <utility>
#include <vector>

namespace atcoder {
    namespace internal {

        template<class E> struct csr {
            std::vector<int> start;
            std::vector<E> elist;
            csr(int n, const std::vector<std::pair<int, E>> &edges)
                : start(n + 1), elist(edges.size()) {
                for (auto e : edges) {
                    start[e.first + 1]++;
                }
                for (int i = 1; i <= n; i++) {
                    start[i] += start[i - 1];
                }
                auto counter = start;
                for (auto e : edges) {
                    elist[counter[e.first]++] = e.second;
                }
            }
        };

// Reference:
// R. Tarjan,
// Depth-First Search and Linear Graph Algorithms
        struct scc_graph {
        public:
            scc_graph(int n) : _n(n) {}

            int num_vertices() { return _n; }

            void add_edge(int from, int to) { edges.push_back({from, {to}}); }

            // @return pair of (# of scc, scc id)
            std::pair<int, std::vector<int>> scc_ids() {
                auto g = csr<edge>(_n, edges);
                int now_ord = 0, group_num = 0;
                std::vector<int> visited, low(_n), ord(_n, -1), ids(_n);
                visited.reserve(_n);
                auto dfs = [&](auto self, int v) -> void {
                    low[v] = ord[v] = now_ord++;
                    visited.push_back(v);
                    for (int i = g.start[v]; i < g.start[v + 1]; i++) {
                        auto to = g.elist[i].to;
                        if (ord[to] == -1) {
                            self(self, to);
                            low[v] = std::min(low[v], low[to]);
                        } else {
                            low[v] = std::min(low[v], ord[to]);
                        }
                    }
                    if (low[v] == ord[v]) {
                        while (true) {
                            int u = visited.back();
                            visited.pop_back();
                            ord[u] = _n;
                            ids[u] = group_num;
                            if (u == v) { break; }
                        }
                        group_num++;
                    }
                };
                for (int i = 0; i < _n; i++) {
                    if (ord[i] == -1) { dfs(dfs, i); }
                }
                for (auto &x : ids) {
                    x = group_num - 1 - x;
                }
                return {group_num, ids};
            }

            std::vector<std::vector<int>> scc() {
                auto ids = scc_ids();
                int group_num = ids.first;
                std::vector<int> counts(group_num);
                for (auto x : ids.second) { counts[x]++; }
                std::vector<std::vector<int>> groups(ids.first);
                for (int i = 0; i < group_num; i++) {
                    groups[i].reserve(counts[i]);
                }
                for (int i = 0; i < _n; i++) {
                    groups[ids.second[i]].push_back(i);
                }
                return groups;
            }

        private:
            int _n;
            struct edge {
                int to;
            };
            std::vector<std::pair<int, edge>> edges;
        };

    }  // namespace internal

}  // namespace atcoder

#include <cassert>
#include <vector>

namespace atcoder {

    struct scc_graph {
    public:
        scc_graph() : internal(0) {}
        scc_graph(int n) : internal(n) {}

        void add_edge(int from, int to) {
            int n = internal.num_vertices();
            assert(0 <= from && from < n);
            assert(0 <= to && to < n);
            internal.add_edge(from, to);
        }

        std::vector<std::vector<int>> scc() { return internal.scc(); }

    private:
        internal::scc_graph internal;
    };

}  // namespace atcoder

using namespace atcoder;

#define int long long
#define rep(i, n) for (int i = 0; i < (int) (n); i++)
#define reps(i, n) for (int i = 1; i <= (int) (n); i++)
#define all(a) (a).begin(), (a).end()
#define uniq(a) (a).erase(unique(all(a)), (a).end())
#define bit(n) (1LL << (n))
#define dump(a) cerr << #a " = " << (a) << endl
using vint = vector<int>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr double PI = 3.1415926535897932384626433832795028;
constexpr int DY[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
constexpr int DX[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
int sign(int a) { return (a > 0) - (a < 0); }
int cdiv(int a, int b) { return (a - 1 + b) / b; }
template<typename T> void fin(T a) {
    cout << a << endl;
    exit(0);
}
template<typename T> T sq(T a) { return a * a; }
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &a) {
    os << "(" << a.first << ", " << a.second << ")";
    return os;
}
template<typename T, typename U, typename V> ostream &operator<<(ostream &os, const tuple<T, U, V> &a) {
    os << "(" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a) << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &a) {
    os << "{";
    for (auto itr = a.begin(); itr != a.end(); itr++) {
        os << *itr << (next(itr) != a.end() ? ", " : "");
    }
    os << "}";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const deque<T> &a) {
    os << "{";
    for (auto itr = a.begin(); itr != a.end(); itr++) {
        os << *itr << (next(itr) != a.end() ? ", " : "");
    }
    os << "}";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const set<T> &a) {
    os << "{";
    for (auto itr = a.begin(); itr != a.end(); itr++) {
        os << *itr << (next(itr) != a.end() ? ", " : "");
    }
    os << "}";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &a) {
    os << "{";
    for (auto itr = a.begin(); itr != a.end(); itr++) {
        os << *itr << (next(itr) != a.end() ? ", " : "");
    }
    os << "}";
    return os;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const map<T, U> &a) {
    os << "{";
    for (auto itr = a.begin(); itr != a.end(); itr++) {
        os << *itr << (next(itr) != a.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

signed main() {
    while (true) {
        int N;
        cin >> N;
        if (N == 0) { break; }
        scc_graph g(N);
        vector adj(N, vint());
        vector<double> p(N);
        rep(i, N) {
            cin >> p[i];
            int m;
            cin >> m;
            rep(j, m) {
                int to;
                cin >> to, to--;
                adj[i].emplace_back(to);
                g.add_edge(i, to);
            }
        }
        auto res = g.scc();
        map<int, int> mp;
        rep(i, res.size()) {
            for (int v:res[i]) {
                mp[v] = i;
            }
        }
        vint active(res.size(), 1);
        rep(i, N) {
            for (int to:adj[i]) {
                if (mp[i] != mp[to]) { active[mp[to]] = 0; }
            }
        }
        double ans = 1;
        rep(i, res.size()) {
            if (!active[i]) { continue; }
            double cur = 1;
            for (int v:res[i]) { cur *= p[v]; }
            ans *= 1 - cur;
        }
        cout << ans << endl;
    }
}
accuracy: 1
time_ms: 10
memory_kb: 3748
final_rank: 14

code_snippet: #include <bits/stdc++.h>
using namespace std;

#include <algorithm>

#include <algorithm>
#include <utility>
#include <vector>

namespace atcoder {
    namespace internal {

        template<class E> struct csr {
            std::vector<int> start;
            std::vector<E> elist;
            csr(int n, const std::vector<std::pair<int, E>> &edges)
                : start(n + 1), elist(edges.size()) {
                for (auto e : edges) {
                    start[e.first + 1]++;
                }
                for (int i = 1; i <= n; i++) {
                    start[i] += start[i - 1];
                }
                auto counter = start;
                for (auto e : edges) {
                    elist[counter[e.first]++] = e.second;
                }
            }
        };

// Reference:
// R. Tarjan,
// Depth-First Search and Linear Graph Algorithms
        struct scc_graph {
        public:
            scc_graph(int n) : _n(n) {}

            int num_vertices() { return _n; }

            void add_edge(int from, int to) { edges.push_back({from, {to}}); }

            // @return pair of (# of scc, scc id)
            std::pair<int, std::vector<int>> scc_ids() {
                auto g = csr<edge>(_n, edges);
                int now_ord = 0, group_num = 0;
                std::vector<int> visited, low(_n), ord(_n, -1), ids(_n);
                visited.reserve(_n);
                auto dfs = [&](auto self, int v) -> void {
                    low[v] = ord[v] = now_ord++;
                    visited.push_back(v);
                    for (int i = g.start[v]; i < g.start[v + 1]; i++) {
                        auto to = g.elist[i].to;
                        if (ord[to] == -1) {
                            self(self, to);
                            low[v] = std::min(low[v], low[to]);
                        } else {
                            low[v] = std::min(low[v], ord[to]);
                        }
                    }
                    if (low[v] == ord[v]) {
                        while (true) {
                            int u = visited.back();
                            visited.pop_back();
                            ord[u] = _n;
                            ids[u] = group_num;
                            if (u == v) { break; }
                        }
                        group_num++;
                    }
                };
                for (int i = 0; i < _n; i++) {
                    if (ord[i] == -1) { dfs(dfs, i); }
                }
                for (auto &x : ids) {
                    x = group_num - 1 - x;
                }
                return {group_num, ids};
            }

            std::vector<std::vector<int>> scc() {
                auto ids = scc_ids();
                int group_num = ids.first;
                std::vector<int> counts(group_num);
                for (auto x : ids.second) { counts[x]++; }
                std::vector<std::vector<int>> groups(ids.first);
                for (int i = 0; i < group_num; i++) {
                    groups[i].reserve(counts[i]);
                }
                for (int i = 0; i < _n; i++) {
                    groups[ids.second[i]].push_back(i);
                }
                return groups;
            }

        private:
            int _n;
            struct edge {
                int to;
            };
            std::vector<std::pair<int, edge>> edges;
        };

    }  // namespace internal

}  // namespace atcoder

#include <cassert>
#include <vector>

namespace atcoder {

    struct scc_graph {
    public:
        scc_graph() : internal(0) {}
        scc_graph(int n) : internal(n) {}

        void add_edge(int from, int to) {
            int n = internal.num_vertices();
            assert(0 <= from && from < n);
            assert(0 <= to && to < n);
            internal.add_edge(from, to);
        }

        std::vector<std::vector<int>> scc() { return internal.scc(); }

    private:
        internal::scc_graph internal;
    };

}  // namespace atcoder

using namespace atcoder;

#define int long long
#define rep(i, n) for (int i = 0; i < (int) (n); i++)
#define reps(i, n) for (int i = 1; i <= (int) (n); i++)
#define all(a) (a).begin(), (a).end()
#define uniq(a) (a).erase(unique(all(a)), (a).end())
#define bit(n) (1LL << (n))
#define dump(a) cerr << #a " = " << (a) << endl
using vint = vector<int>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr double PI = 3.1415926535897932384626433832795028;
constexpr int DY[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
constexpr int DX[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
int sign(int a) { return (a > 0) - (a < 0); }
int cdiv(int a, int b) { return (a - 1 + b) / b; }
template<typename T> void fin(T a) {
    cout << a << endl;
    exit(0);
}
template<typename T> T sq(T a) { return a * a; }
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &a) {
    os << "(" << a.first << ", " << a.second << ")";
    return os;
}
template<typename T, typename U, typename V> ostream &operator<<(ostream &os, const tuple<T, U, V> &a) {
    os << "(" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a) << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &a) {
    os << "{";
    for (auto itr = a.begin(); itr != a.end(); itr++) {
        os << *itr << (next(itr) != a.end() ? ", " : "");
    }
    os << "}";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const deque<T> &a) {
    os << "{";
    for (auto itr = a.begin(); itr != a.end(); itr++) {
        os << *itr << (next(itr) != a.end() ? ", " : "");
    }
    os << "}";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const set<T> &a) {
    os << "{";
    for (auto itr = a.begin(); itr != a.end(); itr++) {
        os << *itr << (next(itr) != a.end() ? ", " : "");
    }
    os << "}";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &a) {
    os << "{";
    for (auto itr = a.begin(); itr != a.end(); itr++) {
        os << *itr << (next(itr) != a.end() ? ", " : "");
    }
    os << "}";
    return os;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const map<T, U> &a) {
    os << "{";
    for (auto itr = a.begin(); itr != a.end(); itr++) {
        os << *itr << (next(itr) != a.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

signed main() {
    while (true) {
        int N;
        cin >> N;
        if (N == 0) { break; }
        scc_graph g(N);
        vector adj(N, vint());
        vector<double> p(N);
        rep(i, N) {
            cin >> p[i];
            int m;
            cin >> m;
            rep(j, m) {
                int to;
                cin >> to, to--;
                adj[i].emplace_back(to);
                g.add_edge(i, to);
            }
        }
        auto res = g.scc();
        map<int, int> mp;
        rep(i, res.size()) {
            for (int v:res[i]) {
                mp[v] = i;
            }
        }
        vint active(res.size(), 1);
        rep(i, N) {
            for (int to:adj[i]) {
                if (mp[i] != mp[to]) { active[mp[to]] = 0; }
            }
        }
        double ans = 1;
        rep(i, res.size()) {
            if (!active[i]) { continue; }
            double cur = 1;
            for (int v:res[i]) { cur *= p[v]; }
            ans *= 1 - cur;
        }
        cout << ans << endl;
    }
}
accuracy: 1
time_ms: 10
memory_kb: 3816
final_rank: 17

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)

class SCC{
private:
    const int V;
    vector<vector<int> > G;
    vector<int> ord,low;
    stack<int> st;
    void dfs(int u,int &tm){
        ord[u] = low[u] = tm++;
        st.push(u);
        for(int v:G[u]){
            if(ord[v] < 0){
                dfs(v,tm);
                low[u] = min(low[u],low[v]);
            }else if(cmp[v] < 0){
                low[u] = min(low[u],ord[v]);
            }
        }
        if(ord[u]==low[u]){
            while(true){
                int v = st.top();
                st.pop();
                cmp[v] = cnt;
                if(v==u)break;
            }
            ++cnt;
        }
    }
public:
    vector<vector<int> > graph;
    vector<int> cmp;
    int cnt;
    SCC(int node_size):V(node_size),G(V),ord(V,-1),low(V),cmp(V,-1),cnt(0){}
    void add_edge(int from,int to){
        G[from].push_back(to);
    }
    int solve(){
        int tm = 0;
        rep(i,V){
            if(ord[i]<0) dfs(i,tm);
        }
        rep(i,V){
            cmp[i] = cnt-1-cmp[i];
        }
        return cnt;
    }
    void make_graph(){
        graph.resize(cnt);
        rep(i,V){
            for(int j:G[i]){
                if(cmp[i]!=cmp[j]){
                    graph[cmp[i]].push_back(cmp[j]);
                }
            }
        }
    }
};
void dfs(vector<vector<int> > &g,vector<bool>&flag,int id){
    for(auto x:g[id]){
        flag[x] = 1;
        dfs(g,flag,x);
    }
}
int main(){
    int n;
    while(cin >> n && n!=0){
        SCC scc(n);
        vector<double> p(n);
        rep(i,n){
            cin >> p[i];
            p[i] = 1.0-p[i];
            int s;
            cin >> s;
            rep(j,s){
                int a;
                cin >> a;
                a--;
                scc.add_edge(i,a);
            }
        }
        int m = scc.solve();
        vector<int> cmp = scc.cmp;
        vector<double> P(m,1.0);
        rep(i,n){
            P[cmp[i]] *= (1.0-p[i]);
        }
        rep(i,m){
            P[i] = 1.0-P[i];
            // cerr << P[i] << endl;
        }
        scc.make_graph();
        auto G = scc.graph;
        vector<bool> flag(m);
        double res = 1.0;
        rep(i,m){
            if(!flag[i]){
                res *= P[i];
                dfs(G,flag,i);
            }
        }
        cout << setprecision(20) << fixed <<  res << "\n";
    }
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3336
final_rank: 2

code_snippet: #include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>
#include <set>

std::vector<int> scc_decompose(const std::vector<std::vector<int>>& G){
  int n = G.size();
  std::vector<int> P;
  {
    std::vector<int> visited(n,false);
    auto dfs = [&](auto dfs, int v) -> void {
      visited[v] = true;
      for(auto v_ : G[v]){
        if(visited[v_]) continue;
        dfs(dfs,v_);
      }
      P.push_back(v);
    };
    for(int i = 0; i < n; ++i){
      if(visited[i]) continue;
      dfs(dfs,i);
    }
    reverse(P.begin(), P.end());
  }
  std::vector<std::vector<int>> G_rev(n);
  for(int i = 0; i < n; ++i){
    for(auto j : G[i])
      G_rev[j].push_back(i);
  }
  std::vector<int> A(n,-1);
  int t = 0;
  auto dfs = [&](auto dfs, int v) -> void {
    A[v] = t;
    for(auto v_ : G_rev[v]){
      if(A[v_] >= 0) continue;
      dfs(dfs,v_);
    }
  };
  for(auto v : P){
    if(A[v] >= 0) continue;
    dfs(dfs,v);
    ++t;
  }
  return A;
}

#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
using namespace std;

bool solve(){
  int N;
  cin >> N;
  if(!N) return false;
  vector<double> P(N);
  vector<vector<int>> G(N);
  vector<pair<int,int>> E;
  for(int i = 0; i < N; ++i){
    cin >> P[i];
    int m;
    cin >> m;
    for(int j = 0; j < m; ++j){
      int v;
      cin >> v;
      --v;
      G[i].emplace_back(v);
    }
  }
  vector<int> A = scc_decompose(G);
  int n = *max_element(A.begin(), A.end()) + 1;
  vector<double> Q(n,1);
  for(int i = 0; i < N; ++i){
    Q[A[i]] *= P[i];
  }
  vector<set<int>> D(n);
  for(int i = 0; i < N; ++i){
    for(auto v : G[i]){
      if(A[v] == A[i]) continue;
      D[A[v]].emplace(A[i]);
    }
  }
  double ans = 1;
  for(int i = 0; i < n; ++i){
    if(D[i].size()) continue;

    ans *= 1 - Q[i];
  }
  cout << setprecision(12) << fixed << ans << '\n';
  return true;
}

int main(){
  while(solve());
}
accuracy: 1
time_ms: 10
memory_kb: 3336
final_rank: 2

code_snippet: #include <bits/stdc++.h>
using namespace std;
struct strongly_connected_components{
  vector<vector<int>> scc;
  vector<int> c;
  void dfs1(vector<vector<int>> &E, vector<bool> &used, vector<int> &t, int v){
    for (int w : E[v]){
      if (!used[w]){
        used[w] = true;
        dfs1(E, used, t, w);
      }
    }
    t.push_back(v);
  }
  void dfs2(vector<vector<int>> &E, vector<bool> &used, int v){
    scc.back().push_back(v);
    for (int w : E[v]){
      if (!used[w]){
        used[w] = true;
        dfs2(E, used, w);
      }
    }
  }
  strongly_connected_components(vector<vector<int>> G){
    int V = G.size();
    vector<vector<int>> E1(V), E2(V);
    for (int i = 0; i < V; i++){
      for (int j : G[i]){
        E1[i].push_back(j);
        E2[j].push_back(i);
      }
    }
    vector<bool> used(V, false);
    vector<int> t;
    for (int i = 0; i < V; i++){
      if (!used[i]){
        used[i] = true;
        dfs1(E1, used, t, i);
      }
    }
    reverse(t.begin(), t.end());
    vector<bool> used2(V, false);
    for (int i = 0; i < V; i++){
      if (!used2[t[i]]){
        used2[t[i]] = true;
        scc.push_back(vector<int>());
        dfs2(E2, used2, t[i]);
      }
    }
    c = vector<int>(V);
    int sz = scc.size();
    for (int i = 0; i < sz; i++){
      for (int j : scc[i]){
        c[j] = i;
      }
    }
  }
  int size(){
    return scc.size();
  }
  int operator [](int k){
    return c[k];
  }
};
int main(){
  cout << fixed << setprecision(9);
  while (1){
    int N;
    cin >> N;
    if (N == 0){
      break;
    }
    vector<double> p(N);
    vector<vector<int>> E(N);
    for (int i = 0; i < N; i++){
      cin >> p[i];
      int m;
      cin >> m;
      for (int j = 0; j < m; j++){
        int a;
        cin >> a;
        a--;
        E[i].push_back(a);
      }
    }
    strongly_connected_components S(E);
    int sz = S.size();
    vector<bool> ok(sz, false);
    vector<double> q(sz, 1);
    for (int i = 0; i < N; i++){
      for (int j : E[i]){
        if (S[i] != S[j]){
          ok[S[j]] = true;
        }
      }
      q[S[i]] *= p[i];
    }
    double ans = 1;
    for (int i = 0; i < sz; i++){
      if (!ok[i]){
        ans *= 1 - q[i];
      }
    }
    cout << ans << endl;
  }
}
accuracy: 1
time_ms: 10
memory_kb: 3396
final_rank: 6

code_snippet: #include <iostream>
#include <cstdio>
#include <vector>
#include <cfloat>
#include <cstring>
#include <cmath>
#include <utility>
using namespace std;
using llong = long long;

llong n;
double p[105];
vector<vector<int>> g;
vector<vector<int>> rg;
vector<int> vs;
int cmp[105];
bool used[105];
double pp[105];
double mem[105];
int indeg[105];

//--- @see ant p.286
void dfs(int v) {
    used[v] = true;
    for (int i = 0; i < g[v].size(); i++) {
        if (!used[g[v][i]]) dfs(g[v][i]);
    }
    vs.push_back(v);
}

void rdfs(int v, int k) {
    used[v] = true;
    cmp[v] = k;
    for (int i = 0; i < rg[v].size(); i++) {
        if (!used[rg[v][i]]) rdfs(rg[v][i], k);
    }
}

int scc() {
    memset(used, 0, sizeof(used));
    vs.clear();
    for (int v = 1; v <= n; v++) {
        if (!used[v]) dfs(v);
    }
    memset(used, 0, sizeof(used));
    int k = 0;
    for (int i = vs.size() - 1; i >= 0; i--) {
        if (!used[vs[i]]) rdfs(vs[i], k++);
    }
    return k;
}
//===

double solve() {
    int m = scc();

    for (int i = 1; i <= n; i++) {
        pp[cmp[i]] *= p[i];
    }

    for (int i = 1; i <= n; i++) {
        for (auto u:g[i]) {
            if (cmp[i] != cmp[u]) indeg[cmp[u]]++;
        }
    }

    double ans = 1;
    for (int i = 0; i < m; i++) {
        if (indeg[i] == 0) ans *= (1 - pp[i]);
    }

    return ans;
}

int main() {
    while (cin >> n, n) {
        g.clear(); rg.clear();
        g.resize(n + 1); rg.resize(n + 1);
        for (int i = 0; i < 105; i++) pp[i] = 1;
        for (int i = 0; i < 105; i++) indeg[i] = 0;
        
        for (int i = 1; i <= n; i++) {
            llong m;
            llong a;
            cin >> p[i];
            cin >> m;
            for (int j = 0; j < m; j++) {
                cin >> a;
                g[i].push_back(a);
                rg[a].push_back(i);
            }
        }

        printf("%.*lf\n", DBL_DIG, solve());
    }
}
accuracy: 1
time_ms: 10
memory_kb: 3396
final_rank: 6

code_snippet: #include<bits/stdc++.h>

using namespace std;
#define INFS (1LL<<28)
#define DEKAI 1000000007
#define INF 1000000007
//#define MOD 1000000007
#define lp(i,n) for(int i=0;i<n;i++)
#define lps(i,n) for(int i=1;i<=n;i++)
#define all(c) begin(c), end(c)

//#define int long long 

namespace {
	#define __DECLARE__(C)    \
	    template <typename T> \
	std::ostream &operator<<(std::ostream &, const C<T> &);

	#define __DECLAREM__(C)               \
	    template <typename T, typename U> \
	std::ostream &operator<<(std::ostream &, const C<T, U> &);

	__DECLARE__(std::vector)
	__DECLARE__(std::deque)
	__DECLARE__(std::set)
	__DECLARE__(std::stack)
	__DECLARE__(std::queue)
	__DECLARE__(std::priority_queue)
	__DECLARE__(std::unordered_set)
	__DECLAREM__(std::map)
	__DECLAREM__(std::unordered_map)

	template <typename T, typename U>
	std::ostream &operator<<(std::ostream &, const std::pair<T, U> &);
	template <typename... T>
	std::ostream &operator<<(std::ostream &, const std::tuple<T...> &);
	template <typename T, std::size_t N>
	std::ostream &operator<<(std::ostream &, const std::array<T, N> &);

	template <typename Tuple, std::size_t N>
	struct __TuplePrinter__ {
		static void print(std::ostream &os, const Tuple &t) {
			__TuplePrinter__<Tuple, N - 1>::print(os, t);
			os << ", " << std::get<N - 1>(t);
		}
	};

	template <typename Tuple>
	struct __TuplePrinter__<Tuple, 1> {
		static void print(std::ostream &os, const Tuple &t) { os << std::get<0>(t); }
	};

	template <typename... T>
	std::ostream &operator<<(std::ostream &os, const std::tuple<T...> &t) {
		os << '(';
		__TuplePrinter__<decltype(t), sizeof...(T)>::print(os, t);
		os << ')';
		return os;
	}

	template <typename T, typename U>
	std::ostream &operator<<(std::ostream &os, const std::pair<T, U> &v) {
		return os << '(' << v.first << ", " << v.second << ')';
	}

	#define __INNER__                             \
	os << '[';                                \
	for (auto it = begin(c); it != end(c);) { \
		os << *it;                            \
		os << (++it != end(c) ? ", " : "");   \
	}                                         \
	return os << ']';

	template <typename T, std::size_t N>
	std::ostream &operator<<(std::ostream &os, const std::array<T, N> &c) {
		__INNER__
	}

	#define __DEFINE__(C)                                           \
	    template <typename T>                                       \
	std::ostream &operator<<(std::ostream &os, const C<T> &c) { \
		__INNER__                                               \
	}

	#define __DEFINEM__(C)                                             \
	    template <typename T, typename U>                              \
	std::ostream &operator<<(std::ostream &os, const C<T, U> &c) { \
		__INNER__                                                  \
	}

	#define __DEFINEW__(C, M1, M2)                                  \
	    template <typename T>                                       \
	std::ostream &operator<<(std::ostream &os, const C<T> &c) { \
		std::deque<T> v;                                        \
		for (auto d = c; !d.empty(); d.pop()) v.M1(d.M2());     \
			return os << v;                                         \
	}

	__DEFINE__(std::vector)
	__DEFINE__(std::deque)
	__DEFINE__(std::set)
	__DEFINEW__(std::stack, push_front, top)
	__DEFINEW__(std::queue, push_back, front)
	__DEFINEW__(std::priority_queue, push_front, top)
	__DEFINE__(std::unordered_set)
	__DEFINEM__(std::map)
	__DEFINEM__(std::unordered_map)
}

#define pii pair<int,int>
#define ll long long
inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

// modint 
template <signed M, unsigned T>
struct mod_int {
	constexpr static signed MODULO = M;
	constexpr static unsigned TABLE_SIZE = T;

	signed x;

	mod_int() : x(0) {}

	mod_int(long long y) : x(static_cast<signed>(y >= 0 ? y % MODULO : MODULO - (-y) % MODULO)) {}

	mod_int(int y) : x(y >= 0 ? y % MODULO : MODULO - (-y) % MODULO) {}

	mod_int &operator+=(const mod_int &rhs) {
		if ((x += rhs.x) >= MODULO) x -= MODULO;
		return *this;
	}

	mod_int &operator-=(const mod_int &rhs) {
		if ((x += MODULO - rhs.x) >= MODULO) x -= MODULO;
		return *this;
	}

	mod_int &operator*=(const mod_int &rhs) {
		x = static_cast<signed>(1LL * x * rhs.x % MODULO);
		return *this;
	}

	mod_int &operator/=(const mod_int &rhs) {
		x = static_cast<signed>((1LL * x * rhs.inv().x) % MODULO);
		return *this;
	}

	mod_int operator-() const { return mod_int(-x); }

	mod_int operator+(const mod_int &rhs) const { return mod_int(*this) += rhs; }

	mod_int operator-(const mod_int &rhs) const { return mod_int(*this) -= rhs; }

	mod_int operator*(const mod_int &rhs) const { return mod_int(*this) *= rhs; }

	mod_int operator/(const mod_int &rhs) const { return mod_int(*this) /= rhs; }

	bool operator<(const mod_int &rhs) const { return x < rhs.x; }

	mod_int inv() const {
		assert(x != 0);
		if (x <= static_cast<signed>(TABLE_SIZE)) {
			if (_inv[1].x == 0) prepare();
			return _inv[x];
		} else {
			signed a = x, b = MODULO, u = 1, v = 0, t;
			while (b) {
				t = a / b;
				a -= t * b;
				std::swap(a, b);
				u -= t * v;
				std::swap(u, v);
			}
			return mod_int(u);
		}
	}

	mod_int pow(long long t) const {
		assert(!(x == 0 && t == 0));
		mod_int e = *this, res = mod_int(1);
		for (; t; e *= e, t >>= 1)
			if (t & 1) res *= e;
		return res;
	}

	mod_int fact() {
		if (_fact[0].x == 0) prepare();
		return _fact[x];
	}

	mod_int inv_fact() {
		if (_fact[0].x == 0) prepare();
		return _inv_fact[x];
	}

	mod_int choose(mod_int y) {
		assert(y.x <= x);
		return this->fact() * y.inv_fact() * mod_int(x - y.x).inv_fact();
	}

	static mod_int _inv[TABLE_SIZE + 1];

	static mod_int _fact[TABLE_SIZE + 1];

	static mod_int _inv_fact[TABLE_SIZE + 1];

	static void prepare() {
		_inv[1] = 1;
		for (int i = 2; i <= (int)TABLE_SIZE; ++i) {
			_inv[i] = 1LL * _inv[MODULO % i].x * (MODULO - MODULO / i) % MODULO;
		}
		_fact[0] = 1;
		for (unsigned i = 1; i <= TABLE_SIZE; ++i) {
			_fact[i] = _fact[i - 1] * int(i);
		}
		_inv_fact[TABLE_SIZE] = _fact[TABLE_SIZE].inv();
		for (int i = (int)TABLE_SIZE - 1; i >= 0; --i) {
			_inv_fact[i] = _inv_fact[i + 1] * (i + 1);
		}
	}
};

template <int M, unsigned F>
std::ostream &operator<<(std::ostream &os, const mod_int<M, F> &rhs) {
	return os << rhs.x;
}

template <int M, unsigned F>
std::istream &operator>>(std::istream &is, mod_int<M, F> &rhs) {
	long long s;
	is >> s;
	rhs = mod_int<M, F>(s);
	return is;
}

template <int M, unsigned F>
mod_int<M, F> mod_int<M, F>::_inv[TABLE_SIZE + 1];

template <int M, unsigned F>
mod_int<M, F> mod_int<M, F>::_fact[TABLE_SIZE + 1];

template <int M, unsigned F>
mod_int<M, F> mod_int<M, F>::_inv_fact[TABLE_SIZE + 1];

template <int M, unsigned F>
bool operator==(const mod_int<M, F> &lhs, const mod_int<M, F> &rhs) {
	return lhs.x == rhs.x;
}

template <int M, unsigned F>
bool operator!=(const mod_int<M, F> &lhs, const mod_int<M, F> &rhs) {
	return !(lhs == rhs);
}

const int MF = 1000010;
const int MOD = 1000000007;

using mint = mod_int<MOD, MF>;

mint binom(int n, int r) { return (r < 0 || r > n || n < 0) ? 0 : mint(n).choose(r); }

mint fact(int n) { return mint(n).fact(); }

mint inv_fact(int n) { return mint(n).inv_fact(); }
const ll mod = 1000000007;
const int MAX_N = 10000;  // 400MB
// const int MAX_N = 1024; // 4MB
// nCr % mod

//#define int long long
#define double long double 

inline ll gcds(ll a, ll b) { return b ? gcds(b, a % b) : a; }
inline ll lcms(ll a, ll b) { return a / gcd(a, b) * b; }

#define RK 200000000000
#define LK 300000000000
#define PL 400000000000
#define MI 500000000000
#define KA 600000000000


using Weight = int;
using Flow = int;
struct Edge {
    int src, dst;
    Weight weight;
    Flow cap;
    Edge() : src(0), dst(0), weight(0) {}
    Edge(int s, int d, Weight w) : src(s), dst(d), weight(w) {}
};
using Edges = std::vector<Edge>;
using Graph = std::vector<Edges>;
using Array = std::vector<Weight>;
using Matrix = std::vector<Array>;

void add_edge(Graph &g, int a, int b, Weight w = 1) {
    g[a].emplace_back(a, b, w);
    g[b].emplace_back(b, a, w);
}
void add_arc(Graph &g, int a, int b, Weight w = 1) { g[a].emplace_back(a, b, w); }

std::vector<int> kosaraju(const Graph &g) {
    int n = g.size(), sz = 0;
    Graph rg(n);
    std::vector<int> stk, cmp(n, -1), added(n), visited(n), ord(n);
    for (auto &es : g) {
        for (auto e : es) {
            std::swap(e.src, e.dst);
            rg[e.src].emplace_back(e);
        }
        sz += es.size();
    }
    stk.resize(n + sz);
    sz = 0;
    for (int i = 0; i < n; i++) {
        if (visited[i]) continue;
        int s = 0;
        stk[s++] = i;
        while (s != 0) {
            int v = stk[s - 1];
            visited[v] = true;
            bool pushed = false;
            for (auto &e : g[v]) {
                int dst = e.dst;
                if (!visited[dst]) {
                    stk[s++] = dst;
                    pushed = true;
                }
            }
            if (pushed) continue;
            int t = stk[s - 1];
            if (!added[t]) {
                added[t] = true;
                ord[n - ++sz] = t;
            }
            --s;
        }
    }
    int k = 0;
    for (int &u : ord) {
        if (cmp[u] != -1) continue;
        int s = 0;
        stk[s++] = u;
        while (s != 0) {
            int v = stk[--s];
            cmp[v] = k;
            for (auto &e : rg[v]) {
                int d = e.dst;
                if (cmp[d] == -1) stk[s++] = d;
            }
        }
        ++k;
    }
    return cmp;
}


signed main(){
	while(1){
		int n;
		cin>>n;
		Graph g(n);
		if(n==0)break;

		vector<bool> check(n,false);
		vector<double> p(n);
		vector<vector<int>> revg(n);

		lp(i,n){
			cin>>p[i];
			int m;
			cin>>m;
			lp(j,m){
				int a;
				cin>>a;
				revg[a-1].push_back(i);
				add_arc(g,i,a-1);
				check[a-1]=true;
			}
		}

		vector<int> cmp=kosaraju(g);
		int maxin=0;
		lp(i,cmp.size()){
			maxin=max(cmp[i],maxin);
		}
		vector<bool> checks(maxin+1,true);
		lp(i,n){
			lp(j,revg[i].size()){
				int now = i;
				int to=revg[i][j];
				if(cmp[now]!=cmp[to]){
					checks[cmp[now]]=false;
				}
			}
		}



		double ans=1;
		lp(i,checks.size()){
			double base=1;
			if(checks[i]){
				lp(j,cmp.size()){
					if(i==cmp[j]){
						base*=p[j];
					}
				}
				ans*=1-base;
			}
		}
		cout<<fixed<<setprecision(15)<<ans<<endl;
	}
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 15344
final_rank: 19

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
#include <stack>

struct SCC {
    int N, p;
    std::vector<std::vector<int> > g, gr, g2i, t, tr;
    std::vector<bool> visited;
    std::vector<int> i2g;
    std::stack<int> order;

    SCC(){}
    SCC(int n){init(n);}
    void init(int n){
        N = n;
        g.clear();
        g.resize(N);
        gr.clear();
        gr.resize(N);
        visited.resize(N);
        i2g.resize(N);
    }
    void add_edge(int u, int v) {
        g[u].emplace_back(v);
        gr[v].emplace_back(u);
    }

    void dfs(int x) {
        if (visited[x]) return;
        visited[x] = true;
        for (int i : g[x]) dfs(i);
        order.push(x);
    }

    void rdfs(int x, int k) {
        if (visited[x]) return;
        visited[x] = true;
        i2g[x] = k;
        for (int i : gr[x]) rdfs(i, k);
    }

    void build() {
        std::fill(visited.begin(), visited.end(), false);
        std::fill(i2g.begin(), i2g.end(), -1);
        for (int i = 0; i < N; i++) dfs(i);
        p = 0;
        std::fill(visited.begin(), visited.end(), false);
        while (!order.empty()) {
            int idx = order.top();
            order.pop();
            if(!visited[idx]) rdfs(idx, p++);
        }
        g2i.clear();
        g2i.resize(p);
        for(int i=0;i<N;i++){
            g2i[i2g[i]].push_back(i);
        }
        t.resize(p);
        tr.resize(p);
        for(int i=0;i<N;i++){
            for (auto &to : g[i]) {
                int x = i2g[i], y = i2g[to];
                if (x == y) continue;
                t[x].push_back(y);
                tr[y].push_back(x);
            }
        }
        for(int i=0;i<p;i++){
            sort(t[i].begin(), t[i].end());
            t[i].erase(unique(t[i].begin(), t[i].end()),t[i].end());
            sort(tr[i].begin(), tr[i].end());
            tr[i].erase(unique(tr[i].begin(), tr[i].end()),tr[i].end());
        }
    }
    int count() const {return p;}
    int operator[](int k) const {return i2g[k];}
};

struct TwoSAT {
    int N;
    SCC scc;
    std::vector<int> v;
    TwoSAT() = default;
    TwoSAT(int n):N(n),scc(n*2){}
    void init(int n){
        N = n;
        scc.init(N*2);
    }
    int neg(int a){return (a+N)%(N*2);}
    void add_edge(int a, int b){
        scc.add_edge(a, b);
    }
    void add_if(int a, int b){
        // a -> b <=> !b -> !a
        add_edge(a,b);
        add_edge(neg(b), neg(a));
    }
    void add_iff(int a, int b){
        // (a <=> b) <=> a -> b and b -> a
        add_if(a, b);
        add_if(b, a);
    }
    void add_or(int a, int b){
        // a or b <=> !a -> b and !b -> a
        add_if(neg(a), b);
    }
    void add_nand(int a, int b){
        // a nand b <=> a -> !b and b -> !a
        add_if(a, neg(b));
    }
    void add_xor(int a, int b){
        add_nand(a, b);
        add_or(a, b);
    }
    void set_true(int a){
        // a <=> !a -> a
        add_edge(neg(a), a);
    }
    void set_false(int a){
        // !a <=> a -> !a
        add_edge(a, neg(a));
    }
    bool build(){
        scc.build();
        bool ok = true;
        for(int i=0;i<N;i++){
            ok &= scc.i2g[i] != scc.i2g[neg(i)];
        }
        if(ok){
            for(int i=0;i<N;i++){
                v.push_back(scc[i] > scc[neg(i)]);
            }
        }
        return ok;
    }
    int operator[](int k) const {return v[k];};
};


int main() {
    while (1) {
        int N;
        double p[100];
        std::cin >> N;
        if (N == 0) break;
        SCC G(N);
        for(int i=0; i<N; i++) {
            std::cin >> p[i];
            int m;
            std::cin >> m;
            for(int j=0; j<m; j++) {
                int a;
                std::cin >> a;
                a--;
                G.add_edge(i, a);
            }
        }
        G.build();
        double ans = 1;
        for (int i=0; i<G.count(); i++) {
            if (G.tr[i].empty()) {
                double q = 1;
                for (int idx : G.g2i[i]) {
                    q *= p[idx];
                }
                ans *= (1 - q);
            }
        }
        printf("%.8lf\n", ans);
    }
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3348
final_rank: 4

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define isIn(x,y,h,w) (x >= 0 && x < h && y >= 0 && y < w)

#define int long long
//using ll = long long;
using P = pair<int,int>;

ostream &operator<<(ostream &os,const P &p){ return os << "(" << p.first << "," << p.second << ")"; }

template<class T> T &chmin(T &a,const T &b){ return a = min(a,b); }
template<class T> T &chmax(T &a,const T &b){ return a = max(a,b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

template<class T>
struct Edge{
	int from,to;
	T cost;
	Edge(int to,T cost) : to(to),cost(cost){}
	Edge(int from,int to,T cost) : from(from),to(to),cost(cost){}
	operator int() const noexcept { return to; }
};

template<class T>
using WeightedGraph = vector<vector<Edge<T>>>;
using Graph = vector<vector<int>>;
template<class T>
using Matrix = vector<vector<T>>;

template<class T>
struct SCC{
	T g;
	Graph G,rG,nG;
	vector<vector<int>> scc;
	vector<int> cmp,used,vs;

	int operator[](int i) const{ return cmp[i]; }
	
	SCC(T g) : g(g),G(g.size()),rG(g.size()),cmp(g.size(),-1),used(g.size()){
		for(int i = 0;i < g.size();i++){
			for(const auto &e : g[i]){
				G[i].push_back((int)e);
				rG[(int)e].push_back(i);
			}
		}
	}

	void dfs(int v){
		used[v] = true;
		for(int to : G[v]) if(!used[to]) dfs(to);
		vs.push_back(v);
	}

	void rdfs(int v,int cnt){
		scc[cnt].push_back(v);
		cmp[v] = cnt;
		for(int to : rG[v]) if(cmp[to] == -1) rdfs(to,cnt);
	}

	void build(){
		int n = g.size(),cnt = 0;
		for(int i = 0;i < n;i++) if(!used[i]) dfs(i);
		reverse(vs.begin(),vs.end());
		for(int v : vs){
			if(cmp[v] == -1){
				scc.emplace_back();
				rdfs(v,cnt++);
			}
		}
		nG.resize(cnt);
		for(int i = 0;i < n;i++){
			for(const auto &e : g[i]){
				int u = cmp[i],v = cmp[(int)e];
				if(u != v) nG[u].push_back(v);
			}
		}
		for(int i = 0;i < cnt;i++){
			sort(nG[i].begin(),nG[i].end());
			nG[i].erase(unique(nG[i].begin(),nG[i].end()),nG[i].end());
		}
	}
};

int n;

void solve(){
	Graph G(n);
	double p[110];
	for(int i = 0;i < n;i++){
		int m;
		cin >> p[i] >> m;
		for(int j = 0;j < m;j++){
			int a;
			cin >> a; a--;
			G[i].push_back(a);
		}
	}
	SCC<Graph> scc(G);
	scc.build();
	int in[110] = {};
	for(int i = 0;i < scc.nG.size();i++){
		for(int to : scc.nG[i]) in[to]++;
	}
	double ans = 1;
	for(int i = 0;i < scc.nG.size();i++){
		if(!in[i]){
			double tmp = 1;
			for(int v : scc.scc[i]) tmp *= p[v];
			ans *= 1.0 - tmp;
		}
	}
	printf("%.14lf\n",ans);
}

signed main(){
	while(cin >> n,n) solve();
}
accuracy: 1
time_ms: 10
memory_kb: 3456
final_rank: 12

code_snippet: #include <bits/stdc++.h>
using namespace std;

struct Strongly_Connected_Component {
  int vsize;
  vector<vector<int>> G, reverseG;
  vector<int> vs, cmp;
  vector<bool> used;
  Strongly_Connected_Component(int newv = 1) {
    vsize = newv;
    G.resize(vsize);
    reverseG.resize(vsize);
    used.resize(vsize, 0);
    cmp.resize(vsize);
  }

  bool add(int from, int to) {
    G[from].push_back(to);
    reverseG[to].push_back(from);
    return 1;
  }
  void dfs(int v) {
    used[v] = true;
    int gvsize = G[v].size();
    for(int i = 0; i < gvsize; ++i)
      if(!used[G[v][i]]) dfs(G[v][i]);
    vs.push_back(v);
  }
  void rdfs(int v, int k) {
    used[v] = true;
    cmp[v] = k;
    int rgvsize = reverseG[v].size();
    for(int i = 0; i < rgvsize; ++i)
      if(!used[reverseG[v][i]]) rdfs(reverseG[v][i], k);
  }
  int solve() {
    used.assign(vsize, 0);
    vs.clear();
    for(int v = 0; v < vsize; ++v)
      if(!used[v]) dfs(v);
    used.assign(vsize, 0);
    int k = 0;
    for(int i = (int)vs.size() - 1; i >= 0; --i)
      if(!used[vs[i]]) rdfs(vs[i], k++);
    return k;
  }
  bool issame(int l, int r) { return cmp[l] == cmp[r]; }
};

long long n;
vector<long double> p, afterp;
vector<vector<bool>> a;
Strongly_Connected_Component scc;

long double solve();

int main() {
  cout << fixed << setprecision(10);
  while(1) {
    cin >> n;
    if(n == 0) break;
    p.resize(n);
    scc = Strongly_Connected_Component(n);
    a.assign(n, vector<bool>(n, 0));
    for(int i = 0; i < n; ++i) {
      int m, to;
      cin >> p[i] >> m;
      for(int j = 0; j < m; ++j) {
        cin >> to;
        scc.add(i, --to);
        a[i][to] = 1;
      }
    }
    cout << solve() << endl;
  }
  return 0;
}

long double solve() {
  long double res = 1;
  int apsize = scc.solve();
  afterp.assign(apsize, 1.0);
  for(int i = 0; i < n; ++i) afterp[scc.cmp[i]] *= p[i];
  for(int i = 0; i < apsize; ++i) {
    bool ch = 1;
    for(int j = 0; j < n; ++j)
      if(scc.cmp[j] == i)
        for(int l = 0; l < n; ++l)
          if(scc.cmp[l] != i && a[l][j]) ch = 0;
    if(ch) res *= 1.0 - afterp[i];
  }
  return res;
}
accuracy: 1
time_ms: 10
memory_kb: 3436
final_rank: 11

code_snippet: #include <bits/stdc++.h>
#define ll long long
using namespace std;

using UnWightedGraph = vector<vector<int> >;
template <typename G>
struct StronglyConnectedComponents {
    const G &g;
    UnWightedGraph gg, rg;
    vector<int> comp, order, used;
    StronglyConnectedComponents(G &g)
        : g(g), gg(g.size()), rg(g.size()), comp(g.size(), -1), used(g.size()) {
        for (int i = 0; i < g.size(); i++) {
            for (auto e : g[i]) {
                gg[i].push_back((int)e);
                rg[(int)e].push_back(i);
            }
        }
    }
    int operator[](int k) { return comp[k]; }

    void dfs(int idx) {
        if (used[idx]) return;
        used[idx] = true;
        for (int to : gg[idx]) dfs(to);
        order.push_back(idx);
    }

    void rdfs(int idx, int cnt) {
        if (comp[idx] != -1) return;
        comp[idx] = cnt;
        for (int to : rg[idx]) rdfs(to, cnt);
    }

    void build(UnWightedGraph &t) {
        for (int i = 0; i < gg.size(); i++) dfs(i);
        reverse(order.begin(), order.end());
        int ptr = 0;
        for (int i : order) {
            if (comp[i] == -1) rdfs(i, ptr), ptr++;
        }
        t.resize(ptr);
        for (int i = 0; i < g.size(); i++) {
            for (auto &to : g[i]) {
                int x = comp[i], y = comp[to];
                if (x == y) continue;
                t[x].push_back(y);
            }
        }
    }
};

int main() {
    int n, m;
    while (cin >> n, n) {
        vector<double> p(n);
        UnWightedGraph g(n), buff;
        for (int i = 0; i < n; i++) {
            cin >> p[i] >> m;
            for (int j = 0; j < m; j++) {
                int a;
                cin >> a;
                a--;
                g[i].push_back(a);
            }
        }
        StronglyConnectedComponents<UnWightedGraph> scc(g);
        scc.build(buff);
        int k = buff.size();
        vector<bool> root(k, true);
        for (int i = 0; i < n; i++) {
            for (int j : g[i]) {
                if (scc[i] != scc[j]) root[scc[j]] = false;
            }
        }
        double ans = 1.0;
        for (int i = 0; i < k; i++) {
            if (root[i]) {
                double q = 1.0;
                for (int j = 0; j < n; j++) {
                    if (scc[j] == i) {
                        q *= p[j];
                    }
                }
                ans *= 1 - q;
            }
        }
        cout << fixed << setprecision(10) << ans << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3408
final_rank: 9