1004. Counting Leaves (30)--dfs

深度优先搜索算法示例
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cmath>

#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <stack>

using namespace std;

int N,M;
struct node
{
    vector<int> child;
}cube[200];

int book[200]={0};
int maxx=-1;
void dfs(int id,int depth)
{
    if(cube[id].child.size()==0)//叶子
    {
        book[depth]++;
        if(depth>maxx)
        {
            maxx=depth;
        }
        return;
    }

    for(int i=0;i<cube[id].child.size();i++)
    {
        dfs(cube[id].child[i],depth+1);
    }

    return;
}

int main()
{
//    freopen("in.txt","r",stdin);

    scanf("%d %d",&N,&M);
    for(int i=0;i<M;i++)
    {
        int id;
        int n;
        scanf("%d %d",&id,&n);
        for(int j=0;j<n;j++)
        {
            int t;
            scanf("%d",&t);
            cube[id].child.push_back(t);
        }
    }

    dfs(1,0);

    for(int i=0;i<=maxx;i++)
    {
        printf("%d",book[i]);
        if(i!=maxx)
            printf(" ");
    }



    return 0;
}





(myenv) (base) E:\paddleDetection\PaddleDetection-release-2.8.1\deploy\pipeline>python deploy/pipeline/pipeline.py --config deploy/pipeline/config/infer_cfg_ppvehicle.yml \ --image_file="E:\屏幕截图_22-7-2025_94834_cn.bing.jpg"--device=gpu E:\anaconda\ana\python.exe: can't open file 'E:\\paddleDetection\\PaddleDetection-release-2.8.1\\deploy\\pipeline\\deploy\\pipeline\\pipeline.py': [Errno 2] No such file or directory (myenv) (base) E:\paddleDetection\PaddleDetection-release-2.8.1\deploy\pipeline>python E:\paddleDetection\PaddleDetection-release-2.8.1/deploy/pipeline/pipeline.py --config deploy/pipeline/config/infer_cfg_ppvehicle.yml \ --image_file="E:\屏幕截图_22-7-2025_94834_cn.bing.jpg"--device=gpu 信息: 用提供的模式无法找到文件。 E:\anaconda\ana\myenv\Lib\site-packages\paddle\utils\cpp_extension\extension_utils.py:715: UserWarning: No ccache found. Please be aware that recompiling all source files may be required. You can download and install ccache from: https://github.com/ccache/ccache/blob/master/doc/INSTALL.md warnings.warn(warning_message) Warning: Unable to use motmetrics in MTMCT in PP-Tracking, please install motmetrics, for example: `pip install motmetrics`, see https://github.com/longcw/py-motmetrics Warning: Unable to use motmetrics in MTMCT in PP-Tracking, please install motmetrics, for example: `pip install motmetrics`, see https://github.com/longcw/py-motmetrics usage: pipeline.py [-h] [-o [OPT ...]] --config CONFIG [--image_file IMAGE_FILE] [--image_dir IMAGE_DIR] [--video_file VIDEO_FILE] [--video_dir VIDEO_DIR] [--rtsp RTSP [RTSP ...]] [--camera_id CAMERA_ID] [--output_dir OUTPUT_DIR] [--pushurl PUSHURL] [--run_mode RUN_MODE] [--device DEVICE] [--enable_mkldnn ENABLE_MKLDNN] [--cpu_threads CPU_THREADS] [--trt_min_shape TRT_MIN_SHAPE] [--trt_max_shape TRT_MAX_SHAPE] [--trt_opt_shape TRT_OPT_SHAPE] [--trt_calib_mode TRT_CALIB_MODE] [--do_entrance_counting] [--do_break_in_counting] [--illegal_parking_time ILLEGAL_PARKING_TIME] [--region_type REGION_TYPE] [--region_polygon REGION_POLYGON [REGION_POLYGON ...]] [--secs_interval SECS_INTERVAL] [--draw_center_traj] pipeline.py: error: unrecognized arguments: \
最新发布
07-25
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值