📖

編集中

2022/12/21に公開約1,100字
fn abc281d(){
    let (n,m) = {
        let mut buff = String::new();
        std::io::stdin().read_line(&mut buff).unwrap();
        let a:Vec<usize> = buff.trim().split_whitespace().map(|x| x.parse().unwrap()).collect();
        (a[0],a[1])
    };
    let graph = getgraph(n, m);
    dbg!(&graph);

    let color = Rc::new(RefCell::new(vec![false;n]));

    

    
}
fn dfs(g:&graph,v:usize,col:i8,color:Rc<RefCell<Vec<i8>>>) -> bool{
    color.borrow_mut()[v] = col;
    for &next in g[v].iter(){
        if color.borrow()[next] != -1{
            if(color.borrow()[next] == col){
                return false;
            }
            continue;
        }

        if !dfs(g, v,1- col, color.clone()){
            return  false;
        }
    }
    return true;

}
fn getgraph(n:usize,m:usize) -> graph{
    let mut vector:graph = vec![vec![];n+1];
    for i in 0..m{
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        let tmp: Vec<usize> = buf.split_whitespace().map(|f|{
            f.parse().unwrap()
        }).collect();
        vector[tmp[0]].push(tmp[1]);
        vector[tmp[1]].push(tmp[0]);
    }

    vector
}

Discussion

ログインするとコメントできます