QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#429297 | #5520. Distance Parities | ship2077 | WA | 0ms | 3812kb | C++14 | 1.1kb | 2024-06-02 11:04:53 | 2024-06-02 11:04:53 |
Judging History
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;
}
详细
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)