QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#109195#6503. DFS Order 3snowy2002RE 0ms0kbC++172.2kb2023-05-27 19:30:002023-05-27 19:30:02

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-27 19:30:02]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2023-05-27 19:30:00]
  • 提交

answer

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#define time chrono::system_clock::now().time_since_epoch().count()
#include<ext/pb_ds/tree_policy.hpp>
#define clean(x) memset(x,0,sizeof(x))
#define fil(x,n) fill(x,x+1+n,0)
#define inf 2000000009
#define maxn 1000005
// #define int long long
using namespace std;
using namespace __gnu_pbds;
mt19937_64 rnd(time);
cc_hash_table<int,int>mp;

int read() {
    int x=1,res=0;
    char c=getchar();
    while(c<'0'||c>'9') {
        if(c=='-') x=-1;
        c=getchar();
    }
    while(c>='0'&&c<='9') {
        res=res*10+(c-'0');
        c=getchar();
    }
    return res*x;
}
struct node {
    int l,r,val;
};
int f[1005][1005];

void solve() {
    int n=read();
    vector id(n+1,vector(n+1,0));
    vector list(n+2,vector<node>(n+2));
    for(int i=1;i<=n;i++) {
        list[i][0].r=1;list[i][n+1].l=n;
        for(int j=1;j<=n;j++) {
            int x=read();
            id[i][x]=j;
            list[i][j].l=j-1;
            list[i][j].r=j+1;
            list[i][j].val=x;
        }
    }
    vector<pair<int,int>>ans;
    
    for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) f[i][j]=0;
    int tot=n;
    while(tot>=2) {
        vector<int>res;
        for(int i=1;i<=n;i++) {
            int a1=list[i][0].r;
            int a2=list[i][a1].r;
            int u=list[i][a1].val,v=list[i][a2].val;
            if(!f[u][v]) {
                f[u][v]=f[v][u]=1;
            }
            int a3=list[i][n+1].l;
            int z=list[i][z].val;
            res.push_back(z);
        }
        for(int i:res) {
            tot--;
            for(int j=1;j<=n;j++) {
                int x=id[j][i];
                int l1=list[j][x].l,r1=list[j][x].r;
                list[j][l1].r=r1;
                list[j][r1].l=l1;
                // s[j].erase({id[j][i],i});
            }
        }
    }
    for(int i=1;i<=n;i++) {
        for(int j=i+1;j<=n;j++) {
            if(f[i][j]) ans.push_back({i,j});
        }
    }
    for(auto [u,v]:ans) {
        printf("%d %d\n",u,v);
    }
}

signed main()
{
    int t=read();
    while(t--) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

4
2
1 2
2 1
3
1 2 3
2 1 3
3 2 1
4
1 2 3 4
2 1 3 4
3 2 4 1
4 2 1 3
5
1 2 4 3 5
2 4 1 3 5
3 5 1 2 4
4 2 1 3 5
5 3 1 2 4

output:


result: