QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#117290 | #6503. DFS Order 3 | aakennes | WA | 102ms | 5724kb | C++14 | 1.3kb | 2023-06-30 20:54:05 | 2023-06-30 20:54:06 |
Judging History
answer
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#define ll long long
using namespace std;
const int maxn=1e3+50,INF=0x3f3f3f3f;
int n,m,a[maxn][maxn],f[maxn],frt[maxn],ed[maxn],exist[maxn][maxn],vis[maxn],pos[maxn];
void Init(){
m=0;
for(int i=1;i<=n;++i){
f[i]=i;pos[i]=n;frt[i]=1,ed[i]=2;vis[i]=0;
for(int j=1;j<=n;++j)exist[i][j]=0;
}
}
int Find(int x){
if(f[x]==x)return x;
return f[x]=Find(f[x]);
}
void Merge(int x,int y){
f[Find(x)]=Find(y);
}
int main() {
//freopen("1.in","r",stdin);
int T;scanf("%d",&T);
while(T--){
scanf("%d",&n);Init();
if(n==1)continue;
for(int i=1;i<=n;++i){
for(int j=1;j<=n;++j){
scanf("%d",&a[i][j]);
}
if(!exist[a[i][1]][a[i][2]])exist[a[i][1]][a[i][2]]=exist[a[i][2]][a[i][1]]=1,m++,printf("%d %d\n",a[i][1],a[i][2]);
}
while(1){
if(m==n-1)goto End;
for(int i=1;i<=n;++i){
while(vis[a[i][pos[i]]])pos[i]--;
vis[a[i][pos[i]]]=1;
for(int j=1;j<=n;++j){
if(vis[a[j][frt[j]]])frt[j]=ed[j],ed[j]++;
while(vis[a[j][ed[j]]])ed[j]++;
if(!exist[frt[j]][ed[j]])exist[frt[j]][ed[j]]=exist[ed[j]][frt[j]]=1,m++,printf("%d %d\n",frt[j],ed[j]);
if(m==n-1)goto End;
}
}
}
End:;
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5656kb
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:
1 2 1 2 3 2 1 2 3 2 4 2 1 2 2 4 3 5 1 3
result:
ok correct answer! (4 test cases)
Test #2:
score: -100
Wrong Answer
time: 102ms
memory: 5724kb
input:
20000 10 1 2 4 5 6 7 3 8 10 9 2 1 4 5 6 7 3 8 10 9 3 8 1 2 4 5 6 7 10 9 4 5 6 7 1 2 3 8 10 9 5 4 6 7 1 2 3 8 10 9 6 7 4 5 1 2 3 8 10 9 7 6 4 5 1 2 3 8 10 9 8 3 1 2 4 5 6 7 10 9 9 10 1 2 4 5 6 7 3 8 10 1 2 4 5 6 7 3 8 9 10 1 4 3 8 2 9 6 5 7 10 2 8 9 6 3 4 1 5 7 10 3 8 2 9 6 4 1 5 7 10 4 1 3 8 2 9 6 5...
output:
1 2 3 8 4 5 6 7 9 10 10 1 2 3 3 4 1 3 1 4 2 8 3 8 5 4 6 9 7 5 10 7 1 2 2 3 1 9 2 4 3 10 5 6 7 5 8 2 1 2 1 3 2 3 1 6 2 4 3 8 5 7 9 6 10 2 1 2 1 3 2 3 1 9 2 10 3 6 4 7 5 1 8 9 1 2 2 3 1 3 1 10 2 6 3 8 4 8 5 10 7 9 1 2 2 3 1 3 1 10 2 3 3 7 4 8 5 8 6 7 9 2 1 2 1 3 1 4 2 3 4 2 5 10 6 7 8 4 9 1 1 2 1 3 1 ...
result:
wrong answer your output is not a tree (test case 1)