QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#429296 | #5520. Distance Parities | ship2077 | WA | 0ms | 3736kb | C++14 | 1.1kb | 2024-06-02 11:04:30 | 2024-06-02 11:04:31 |
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,y);
}
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: 3736kb
input:
3 3 011 101 110 4 0100 1000 0001 0010 5 01010 10101 01010 10101 01010
output:
YES 0 1 0 2 1 2 NO YES 0 1 0 2 0 3 0 4 1 2 1 3 1 4 2 3 2 4 3 4
result:
wrong answer Integer 0 violates the range [2, 3] (test case 1)