提交记录 11531
用户 | 题目 | 状态 | 得分 | 用时 | 内存 | 语言 | 代码长度 |
---|---|---|---|---|---|---|---|
boboy | noip18d. 【NOIP2018】旅行 | Accepted | 100 | 578.071 ms | 676 KB | C++ | 1.91 KB |
提交时间 | 评测时间 |
---|---|
2020-01-26 11:48:10 | 2020-08-01 02:45:03 |
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<vector>
using namespace std;
inline int read(){
int ans=0;
char a=getchar();
while('0'>a||a>'9'){
a=getchar();
}
while('0'<=a&&a<='9'){
ans=ans*10+a-'0';
a=getchar();
}
return ans;
}
vector<int>edge[5005];
struct node{
int next,tot;
};
vector<node>edge1[5005];
int n,m;
int out[5005],fst[5005],nout[5005],now,cut;
bool been[5005];
void dfs(int u){
been[u]=1;
for(int i=0;i<edge[u].size();i++){
int v=edge[u][i];
if(!been[v]){
nout[now++]=v;
dfs(v);
}
}
}
void dfs1(int u){
been[u]=1;
for(register int i=0;i<edge1[u].size();i++){
node v=edge1[u][i];
if(v.tot==cut)continue;
if(been[v.next]==0){
nout[now++]=v.next;
dfs1(v.next);
}
}
}
inline bool cmp(node x,node y){
return x.next<y.next;
}
int main(){
n=read(),m=read();
if(n-1==m){
for(int i=1;i<=m;i++){
int x=read(),y=read();
edge[x].push_back(y);
edge[y].push_back(x);
}
for(int i=1;i<=n;i++){
sort(edge[i].begin(),edge[i].end());
}
fst[1]=-1;
now=2;
nout[1]=1;
dfs(1);
for(int i=1;i<=n;i++){
printf("%d ",nout[i]);
}
}
else{
for(register int i=1;i<=m;i++){
int x=read(),y=read();
edge1[x].push_back(node{y,i});
edge1[y].push_back(node{x,i});
}
for(register int i=1;i<=n;i++){
sort(edge1[i].begin(),edge1[i].end(),cmp);
}
bool flag=0;
for(cut=1;cut<=m;cut++){
memset(been,0,sizeof(been));
nout[1]=1;
now=2;
dfs1(1);
if(now>n){
if(!flag){
for(int i=1;i<=n;i++){
out[i]=nout[i];
}
}
else{
bool flag1=1;
for(register int i=1;i<=n;i++){
if(nout[i]>out[i]){
flag1=0;
break;
}
if(nout[i]<out[i])break;
}
if(flag1){
for(int i=1;i<=n;i++){
out[i]=nout[i];
}
}
}
flag=1;
}
}
for(register int i=1;i<=n;i++){
printf("%d ",out[i]);
}
puts("");
}
return 0;
}
Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
Testcase #1 | 75.16 us | 280 KB | Accepted | Score: 4 | 显示更多 |
Testcase #2 | 79.4 us | 280 KB | Accepted | Score: 4 | 显示更多 |
Testcase #3 | 73.33 us | 280 KB | Accepted | Score: 4 | 显示更多 |
Testcase #4 | 97.92 us | 284 KB | Accepted | Score: 4 | 显示更多 |
Testcase #5 | 96.47 us | 284 KB | Accepted | Score: 4 | 显示更多 |
Testcase #6 | 326.22 us | 348 KB | Accepted | Score: 4 | 显示更多 |
Testcase #7 | 329.73 us | 352 KB | Accepted | Score: 4 | 显示更多 |
Testcase #8 | 328.5 us | 356 KB | Accepted | Score: 4 | 显示更多 |
Testcase #9 | 334.37 us | 340 KB | Accepted | Score: 4 | 显示更多 |
Testcase #10 | 333.48 us | 336 KB | Accepted | Score: 4 | 显示更多 |
Testcase #11 | 1.473 ms | 576 KB | Accepted | Score: 4 | 显示更多 |
Testcase #12 | 1.48 ms | 616 KB | Accepted | Score: 4 | 显示更多 |
Testcase #13 | 1.474 ms | 628 KB | Accepted | Score: 4 | 显示更多 |
Testcase #14 | 1.467 ms | 576 KB | Accepted | Score: 4 | 显示更多 |
Testcase #15 | 1.469 ms | 656 KB | Accepted | Score: 4 | 显示更多 |
Testcase #16 | 77.22 us | 280 KB | Accepted | Score: 4 | 显示更多 |
Testcase #17 | 74.95 us | 280 KB | Accepted | Score: 4 | 显示更多 |
Testcase #18 | 169.63 us | 284 KB | Accepted | Score: 4 | 显示更多 |
Testcase #19 | 170.72 us | 284 KB | Accepted | Score: 4 | 显示更多 |
Testcase #20 | 11.141 ms | 364 KB | Accepted | Score: 4 | 显示更多 |
Testcase #21 | 11.293 ms | 364 KB | Accepted | Score: 4 | 显示更多 |
Testcase #22 | 11.576 ms | 364 KB | Accepted | Score: 4 | 显示更多 |
Testcase #23 | 574.598 ms | 676 KB | Accepted | Score: 4 | 显示更多 |
Testcase #24 | 576.931 ms | 668 KB | Accepted | Score: 4 | 显示更多 |
Testcase #25 | 578.071 ms | 660 KB | Accepted | Score: 4 | 显示更多 |
Judge Duck Online | 评测鸭在线
Server Time: 2024-11-22 23:48:21 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠