提交记录 49365


用户 题目 状态 得分 用时 内存 语言 代码长度
saffah_dsh_v41_0919 noip18d. 【NOIP2018】旅行 Accepted 100 424.607 ms 608 KB C++17 1.71 KB
提交时间 评测时间
2026-09-19 15:55:33 2026-09-19 15:56:16
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <string.h>
using namespace std;
static int n,m;
static vector<int> adj[5005];
static int vis[5005], cur[5005], bestseq[5005], cnt;
static int bu,bv;
static void dfs(int u){
    vis[u]=1; cur[cnt++]=u;
    for(size_t i=0;i<adj[u].size();i++){
        int v=adj[u][i];
        if(vis[v]) continue;
        if((u==bu&&v==bv)||(u==bv&&v==bu)) continue;
        dfs(v);
    }
}
int main(){
    if(scanf("%d %d",&n,&m)!=2) return 0;
    for(int i=0;i<m;i++){int a,b;scanf("%d %d",&a,&b);adj[a].push_back(b);adj[b].push_back(a);}
    for(int i=1;i<=n;i++) sort(adj[i].begin(),adj[i].end());
    if(m==n-1){
        bu=bv=-1; cnt=0; memset(vis,0,sizeof vis); dfs(1);
        for(int i=0;i<n;i++) printf("%d%c",cur[i],i+1<n?' ':'\n');
        return 0;
    }
    static int deg[5005]; static char rem[5005];
    static int q[5005];
    for(int i=1;i<=n;i++) deg[i]=(int)adj[i].size();
    int qh=0,qt=0;
    for(int i=1;i<=n;i++) if(deg[i]==1) q[qt++]=i;
    while(qh<qt){
        int u=q[qh++]; rem[u]=1;
        for(size_t i=0;i<adj[u].size();i++){ int v=adj[u][i]; if(!rem[v] && --deg[v]==1) q[qt++]=v; }
    }
    static int cu[5005],cv[5005]; int nc=0;
    for(int u=1;u<=n;u++) if(!rem[u]) for(size_t i=0;i<adj[u].size();i++){ int v=adj[u][i]; if(!rem[v]&&u<v){ cu[nc]=u; cv[nc]=v; nc++; } }
    int have=0;
    for(int e=0;e<nc;e++){
        bu=cu[e]; bv=cv[e]; cnt=0; memset(vis,0,sizeof vis); dfs(1);
        if(!have){ memcpy(bestseq,cur,sizeof(int)*n); have=1; }
        else { for(int i=0;i<n;i++){ if(cur[i]!=bestseq[i]){ if(cur[i]<bestseq[i]) memcpy(bestseq,cur,sizeof(int)*n); break; } } }
    }
    for(int i=0;i<n;i++) printf("%d%c",bestseq[i],i+1<n?' ':'\n');
    return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #138.92 us176 KBAcceptedScore: 4

Testcase #234.09 us176 KBAcceptedScore: 4

Testcase #333.55 us176 KBAcceptedScore: 4

Testcase #466.16 us184 KBAcceptedScore: 4

Testcase #566.67 us184 KBAcceptedScore: 4

Testcase #6375.14 us244 KBAcceptedScore: 4

Testcase #7373.81 us248 KBAcceptedScore: 4

Testcase #8374.52 us252 KBAcceptedScore: 4

Testcase #9379.41 us236 KBAcceptedScore: 4

Testcase #10378.29 us232 KBAcceptedScore: 4

Testcase #111.853 ms476 KBAcceptedScore: 4

Testcase #121.851 ms512 KBAcceptedScore: 4

Testcase #131.841 ms524 KBAcceptedScore: 4

Testcase #141.848 ms472 KBAcceptedScore: 4

Testcase #151.845 ms552 KBAcceptedScore: 4

Testcase #1637.6 us192 KBAcceptedScore: 4

Testcase #1736.82 us192 KBAcceptedScore: 4

Testcase #18117.65 us200 KBAcceptedScore: 4

Testcase #19114.74 us200 KBAcceptedScore: 4

Testcase #2012.744 ms276 KBAcceptedScore: 4

Testcase #2112.779 ms276 KBAcceptedScore: 4

Testcase #2213.154 ms276 KBAcceptedScore: 4

Testcase #23424.607 ms608 KBAcceptedScore: 4

Testcase #24394.651 ms596 KBAcceptedScore: 4

Testcase #25368.388 ms588 KBAcceptedScore: 4


Judge Duck Online | 评测鸭在线
Server Time: 2026-09-23 12:07:15 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠