1 条题解

  • 0
    @ 2025-10-8 16:57:05
    #include <bits/stdc++.h>
    using namespace std;
    
    const int N = 11100, M = 51100;
    struct edge{int x,y,pre;}a[M*2];int alen,last[N];
    void ins(int x,int y){++alen;a[alen]=edge{x,y,last[x]};last[x]=alen;}
    vector<int>path;
    void oula(int x)
    {
        for(int k=last[x];k;k=last[x])
        {
            last[x]=a[k].pre;
    		oula(a[k].y);	
        }
    	path.push_back(x);
    }
    
    int main()
    {
        int n,m;scanf("%d%d",&n,&m);
        alen=0;memset(last,0,sizeof(last));
        for(int i=1;i<=m;i++){int x,y;scanf("%d%d",&x,&y);ins(x,y);ins(y,x);}
        oula(1);
        for(int i=path.size();i>=1;i--)printf("%d\n",path[i-1]);
    	return 0;
    }
    
    • 1

    D166 欧拉回路 [USACO05JAN] Watchcow S

    信息

    ID
    1454
    时间
    1000ms
    内存
    128MiB
    难度
    7
    标签
    递交数
    165
    已通过
    40
    上传者