結果

問題 No.3315 FPS Game
コンテスト
ユーザー 👑 ArcAki
提出日時 2025-03-02 04:25:52
言語 Rust
(1.83.0 + proconio)
結果
TLE  
実行時間 -
コード長 3,059 bytes
コンパイル時間 13,388 ms
コンパイル使用メモリ 400,912 KB
実行使用メモリ 43,044 KB
最終ジャッジ日時 2025-05-02 20:02:14
合計ジャッジ時間 21,237 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 15 TLE * 1 -- * 9
権限があれば一括ダウンロードができます

ソースコード

diff #

#[allow(unused_imports)]
use std::{
    cell::RefCell, convert::{Infallible, TryFrom, TryInto as _},
    fmt::{self, Debug, Display, Formatter,},
    fs::{File}, hash::{Hash, Hasher}, iter::{Product, Sum}, marker::PhantomData,
    ops::{Add, AddAssign, Sub, SubAssign, Div, DivAssign, Mul, MulAssign, Neg, },
    str::FromStr, sync::{atomic::{self, AtomicU32, AtomicU64}, Once}, collections::{*},
    mem::{swap}, cmp::{self, Reverse, Ordering, Eq, PartialEq, PartialOrd},
    thread::LocalKey, f64::consts::PI, time::Instant,
    io::{self, stdin, Read, read_to_string, BufWriter, BufReader, stdout, Write},
};
#[allow(unused_imports)]
use proconio::{input, input_interactive, marker::{*}};
#[allow(unused_imports)]
//use rand::{thread_rng, Rng, seq::SliceRandom};
#[allow(unused_imports)]
//use ac_library::{*};

#[allow(dead_code)]
const INF: i64 = 1<<60;
#[allow(dead_code)]
const MOD: i64 = 998244353;
#[allow(dead_code)]
const D: [(usize, usize); 4] = [(1, 0), (0, 1), (!0, 0), (0, !0)];

use proconio::fastout;
#[fastout]
fn main(){
    input!{
        n: usize, s: Usize1, t: Usize1,
        e: [(Usize1, Usize1); n-1],
    }
    let mut edge = vec![Vec::new(); n];
    let mut cnt = vec![0; n];
    for (i, &(u, v)) in e.iter().enumerate(){
        cnt[u] += 1; cnt[v] += 1;
        edge[u].push((v, i)); edge[v].push((u, i));
    }
    let mut way = Vec::new();
    let (u, v) = e[s];
    way.push(u);
    if !dfs(u, v, t, &edge, &mut way){
        way[0] = v;
        dfs(v, u, t, &edge, &mut way);
    }
    let mut f=vec![1; n+10];
    let mut z = 1i64;
    let mut inv = vec![1; n+10];
    for i in 2..n as i64+1{
        z=(z*i)%MOD;
        let w=(MOD-inv[(MOD%i)as usize]*(MOD/i)%MOD)%MOD;
        inv[i as usize] = w;
        f[i as usize] = z;
    }
    for i in 1..n{
        inv[i+1] = (inv[i+1]*inv[i])%MOD;
    }
    let mut heap = BinaryHeap::new();
    for &v in &way{
        let c = cnt[v]-2;
        let mut vc = vec![0];
        for i in 0..=c{
            vc.push(f[c]*inv[c-i]%MOD);
        }
        heap.push((Reverse(vc.len()), vc));
    }
    while heap.len() > 1{
        let (_, v1) = heap.pop().unwrap();
        let (_, v2) = heap.pop().unwrap();
        let mut nex = vec![0; v1.len()+v2.len()-1];
        for (i, &x1) in v1.iter().enumerate(){
            for (j, &x2) in v2.iter().enumerate(){
                nex[i+j] = (nex[i+j]+x1*x2)%MOD;
            }
        }
        heap.push((Reverse(nex.len()), nex));
    }
    let (_, res) = heap.pop().unwrap();
    let mut ans = vec![0; n];
    for (i, &x) in res.iter().enumerate(){
        ans[i] = x;
    }
    println!("{}", ans.iter().map(|x| x.to_string()).collect::<Vec<_>>().join(" "));
}

fn dfs(p: usize, pre: usize, t: usize, edge: &Vec<Vec<(usize, usize)>>, way: &mut Vec<usize>)->bool{
    for &(nex, idx) in &edge[p]{
        if nex==pre{continue}
        way.push(nex);
        if idx==t{
            way.pop();
            return true;
        } else if dfs(nex, p, t, edge, way){
            return true;
        }
        way.pop();
    }
    false
}
0