求助万能的谷民
  • 板块学术版
  • 楼主shinzanmonoszm 妹妹
  • 当前回复3
  • 已保存回复3
  • 发布时间2023/8/9 12:06
  • 上次更新2023/11/3 05:00:31
查看原帖
求助万能的谷民
610557
shinzanmonoszm 妹妹楼主2023/8/9 12:06

再求欧拉回路的时候,当前弧优化第一种就能 AC,第二种和第三种会 TLE,如何解释。

void dfs(int u){
    for(int &tmp=head[u];tmp;tmp=graph[tmp].nxt){
        int p=tmp;
        if(vis[p])continue;
        vis[p]=true;
        dfs(graph[p].to);
        s.push(graph[p].id);
    }
}
void dfs(int u){
    for(int p=head[u];p;p=graph[p].nxt){
        head[u]=p;
        if(vis[p])continue;
        vis[p]=true;
        dfs(graph[p].to);
        s.push(graph[p].id);
    }
}
void dfs(int u){
    for(int p=head[u];p;p=graph[p].nxt){
        head[u]=graph[p].nxt;
        if(vis[p])continue;
        vis[p]=true;
        dfs(graph[p].to);
        s.push(graph[p].id);
    }
}
2023/8/9 12:06
加载中...