QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#376810#6109. Similarity Graphfairyqq28WA 1ms3936kbC++141.5kb2024-04-04 16:53:572024-04-04 16:53:58

Judging History

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

  • [2024-04-04 16:53:58]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3936kb
  • [2024-04-04 16:53:57]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<algorithm>
#define rep(i, a, b) for(int i = (a); i <= (b); i++)
#define per(i, a, b) for(int i = (a); i >= (b); i--)
using namespace std;
const int N = 110;
int n, f[10010], p[N], q[N], ans1[N], ans2[N];
bool a[N][N], v[N][N];
inline int id(int x, int y) {return (x - 1) * n + y - 1;}
int find(int x) {return x == f[x] ? x : f[x] = find(f[x]);}
inline bool cmp(int x, int y) {return v[x][y];}
inline void merge(int x, int y) {f[find(x)] = find(y);}

int main(){
    scanf("%d", &n);
    rep(i, 1, n) rep(j, 1, n){
        scanf("%d", &a[i][j]);
        f[id(i, j)] = id(i, j);
    }
    rep(i, 1, n) rep(j, 1, n) rep(k, 1, n)
        if(a[i][j] == a[i][k] && a[i][k] == 1-a[j][k])
            merge(id(i, j), id(i, k)), merge(id(j, i), id(k, i));
    rep(i, 1, n) rep(j, i + 1, n){
        if(find(id(i, j)) == find(id(j, i))){
            puts("NO"); return 0;
        }
        v[i][j] = find(id(i, j)) < find(id(i, j));
        v[j][i] = !v[i][j];
    }
    puts("YES");
    rep(i, 1, n) p[i] = i, q[i] = i;
    sort(p + 1, p + n + 1, cmp);
    rep(i, 1, n) rep(j, i + 1, n){
        // printf("pre: %d %d %d\n", i, j, v[i][j]);
        v[i][j] ^= a[i][j] ^ 1;
        // printf("now: %d %d %d\n", i, j, v[i][j]);
        v[j][i] = !v[i][j];
    }
    sort(q + 1, q + n + 1, cmp);
    rep(i, 1, n) ans1[p[i]] = i, ans2[q[i]] = i;
    rep(i, 1, n) printf("%d ", ans1[i]); puts("");
    rep(i, 1, n) printf("%d ", ans2[i]); puts("");
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3936kb

input:

4
0 1 0 1
1 0 0 0
0 0 0 1
1 0 1 0

output:

YES
4 3 2 1 
3 1 4 2 

result:

ok ok

Test #2:

score: 0
Accepted
time: 0ms
memory: 3620kb

input:

6
0 1 0 1 0 1
1 0 0 0 1 0
0 0 0 1 1 1
1 0 1 0 0 0
0 1 1 0 0 0
1 0 1 0 0 0

output:

NO

result:

ok ok

Test #3:

score: 0
Accepted
time: 0ms
memory: 3924kb

input:

1
0

output:

YES
1 
1 

result:

ok ok

Test #4:

score: 0
Accepted
time: 0ms
memory: 3828kb

input:

2
0 0
0 0

output:

YES
2 1 
1 2 

result:

ok ok

Test #5:

score: 0
Accepted
time: 0ms
memory: 3804kb

input:

2
0 1
1 0

output:

YES
2 1 
2 1 

result:

ok ok

Test #6:

score: 0
Accepted
time: 0ms
memory: 3936kb

input:

3
0 0 0
0 0 0
0 0 0

output:

YES
3 2 1 
1 2 3 

result:

ok ok

Test #7:

score: 0
Accepted
time: 0ms
memory: 3896kb

input:

3
0 0 0
0 0 1
0 1 0

output:

YES
3 2 1 
1 3 2 

result:

ok ok

Test #8:

score: -100
Wrong Answer
time: 0ms
memory: 3808kb

input:

3
0 0 1
0 0 0
1 0 0

output:

YES
3 2 1 
2 3 1 

result:

wrong answer found wrong p and q