QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#667068#7158. Carnival GeneralWarinchai_s#0 0ms0kbC++141.7kb2024-10-22 20:56:142024-10-22 20:56:28

Judging History

你现在查看的是最新测评结果

  • [2024-10-22 20:56:28]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:0kb
  • [2024-10-22 20:56:14]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int r[1005][1005];
int no[1005][1005];
vector<int>adj[1005];
vector<int>rv[1005];
int in[1005];
int vis[1005];
int bf[1005];
priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>pq;
int st=0;
int cnt=0;
int n;
void dfs(int u,int p=-1){
    bf[u]=p;
    st=u;
    cnt++;
    int mn=1e4,id=-1;
    for(auto x:adj[u])if(x!=p)if(!vis[x]&&in[x]<mn)mn=in[x],id=x;
    if(id==-1){
        assert(cnt==n);
        return;
    }
    vis[id]=1;
    dfs(id,u);
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>n;
    for(int i=0;i<n;i++){
        //cerr<<"i:"<<i<<"\n";
        for(int j=0;j<i;j++){
            cin>>r[i][j];
            if(j>(i/2)){
                no[i][r[i][j]]=1;
                no[r[i][j]][i]=1;
            }
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(i==j)continue;
            if(!no[i][j])adj[i].push_back(j),adj[j].push_back(i),in[j]++,in[i]++;
        }
    }
    for(int i=0;i<n;i++){
        pq.push({in[i],i});
    }
    auto [a,b]=pq.top();
    pq.pop();
    vis[b]=1;
    dfs(b);
    int x=0;
    vector<int>v;
    while(st!=-1){
        //cout<<st<<" ";
        v.push_back(st);
        st=bf[st];
    }
    assert(v.size()==n);
    for(int i=1;i<n-1;i++){
        assert(no[v[i]][v[i-1]]==0);
        assert(no[v[i-1]][v[i]]==0);
        assert(no[v[i+1]][v[i]]==0);
        assert(no[v[i]][v[i+1]]==0);
    }
    assert(no[v[0]][v[1]]==0);
    assert(no[v[n-2]][v[n-1]]==0);
    map<int,int>mp;
    for(auto x:v){
        assert(mp[x]==0);
        mp[x]++;
    }
    assert(0);
    for(auto x:v)cout<<x<<" ";
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Runtime Error

Test #1:

score: 0
Runtime Error

input:

2
0

output:


result:


Subtask #2:

score: 0
Runtime Error

Test #6:

score: 0
Runtime Error

input:

2
0

output:


result:


Subtask #3:

score: 0
Runtime Error

Test #12:

score: 0
Runtime Error

input:

2
0

output:


result:


Subtask #4:

score: 0
Skipped

Dependency #1:

0%