QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#429297#5520. Distance Paritiesship2077WA 0ms3812kbC++141.1kb2024-06-02 11:04:532024-06-02 11:04:53

Judging History

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

  • [2024-06-02 11:04:53]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3812kb
  • [2024-06-02 11:04:53]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
constexpr int M=505;
int n,d[M][M];string str[M];
int read(){
    int x=0;char ch=getchar();
    while (!isdigit(ch)) ch=getchar();
    while (isdigit(ch)) x=x*10+ch-48,ch=getchar();
    return x;
}
void solve(){ cin>>n;
    for (int i=0;i<n;i++)
        for (int j=0;j<n;j++)
            d[i][j]=i==j?0:0x3f3f3f3f;
    for (int i=0;i<n;i++){
        cin>>str[i];
        for (int j=0;j<n;j++)
            if (str[i][j]=='1')
                d[i][j]=1;
    }
    for (int k=0;k<n;k++)
        for (int i=0;i<n;i++)
            for (int j=0;j<n;j++)
                d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
    for (int i=0;i<n;i++)
        for (int j=0;j<n;j++)
            if (d[i][j]==0x3f3f3f3f||(d[i][j]&1)!=(str[i][j]=='1'))
                return puts("NO"),void();
    puts("YES");
    vector<pair<int,int>>edge;
    for (int i=0;i<n;i++)
        for (int j=i+1;j<n;j++)
            if (d[i][j]) edge.emplace_back(i,j);
    for (auto [x,y]:edge) printf("%d %d\n",x+1,y+1);
}
int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int T;cin>>T;while (T--) solve();return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3812kb

input:

3
3
011
101
110
4
0100
1000
0001
0010
5
01010
10101
01010
10101
01010

output:

YES
1 2
1 3
2 3
NO
YES
1 2
1 3
1 4
1 5
2 3
2 4
2 5
3 4
3 5
4 5

result:

wrong answer Integer 1 violates the range [2, 3] (test case 1)