提交记录 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;
}
| Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
| Testcase #1 | 38.92 us | 176 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #2 | 34.09 us | 176 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #3 | 33.55 us | 176 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #4 | 66.16 us | 184 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #5 | 66.67 us | 184 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #6 | 375.14 us | 244 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #7 | 373.81 us | 248 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #8 | 374.52 us | 252 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #9 | 379.41 us | 236 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #10 | 378.29 us | 232 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #11 | 1.853 ms | 476 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #12 | 1.851 ms | 512 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #13 | 1.841 ms | 524 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #14 | 1.848 ms | 472 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #15 | 1.845 ms | 552 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #16 | 37.6 us | 192 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #17 | 36.82 us | 192 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #18 | 117.65 us | 200 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #19 | 114.74 us | 200 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #20 | 12.744 ms | 276 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #21 | 12.779 ms | 276 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #22 | 13.154 ms | 276 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #23 | 424.607 ms | 608 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #24 | 394.651 ms | 596 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #25 | 368.388 ms | 588 KB | Accepted | Score: 4 | 显示更多 |
Judge Duck Online | 评测鸭在线
Server Time: 2026-09-23 12:07:15 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠