QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#512274#5520. Distance ParitieshuayucaijiWA 190ms6256kbC++141.4kb2024-08-10 14:00:312024-08-10 14:00:36

Judging History

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

  • [2024-08-10 14:00:36]
  • 评测
  • 测评结果:WA
  • 用时:190ms
  • 内存:6256kb
  • [2024-08-10 14:00:31]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N =505;
int n,vst[N],ecnt;
char s[N];
vector<int> to[N];
int mp[N][N],ori[N][N];
void dfs(int x,int dep){
  if(dep>3) return;
  vst[x]=1;
  for(int t:to[x]){
    if(vst[t]) continue;
    dfs(t,dep+1);
  }
}
void solve(){
  cin>>n;
  ecnt=0;
  for(int i=1;i<=n;i++){
    cin>>s;
    for(int j=0;j<n;j++){
      if(s[j]=='1'){
        to[i].push_back(j+1);
        ecnt++;
        ori[i][j+1]=mp[i][j+1]=1;
      }else{
        mp[i][j+1]=1e8;
        ori[i][j+1]=0;
      }
    }
    mp[i][i]=0;
  }
  int flag=1;
  for(int j=1;j<=n;j++){
    for(int i=1;i<=n;i++) vst[i]=0;
    dfs(j,1);
    for(int i=1;i<=n;i++) flag&=vst[i];
  }
  if(flag){
    for(int k=1;k<=n;k++){
      for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
          mp[i][j]=min(mp[i][j],mp[i][k]+mp[k][j]);
        }
      }
    }
    for(int i=1;i<=n;i++){
      for(int j=1;j<=n;j++){
        if(ori[i][j]!=mp[i][j]%2){
          exit(1);
        }
      }
    }
    cout<<"YES\n";
    cout<<ecnt/2<<endl;
    for(int i=1;i<=n;i++){
      for(int j:to[i]){
        if(i<j){
          cout<<i<<' '<<j<<endl;
        }
      }
    }
  }else{
    cout<<"NO\n";
  }
  for(int i=1;i<=n;i++) to[i].clear();
}
signed main(){
  ios::sync_with_stdio(false);
  int t;
  cin>>t;
  while(t--)solve();
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3660kb

input:

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

output:

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

result:

ok Correct (3 test cases)

Test #2:

score: -100
Wrong Answer
time: 190ms
memory: 6256kb

input:

1
500
001001010000101001100000100011101011010001100110010000011000001100000011010001001111001010010101110100000100011000110111100010001000010111111000000101101010011111000010110010111100111110111000010000100100010010001110000100111000001111101011111101111110111110001000111110001011111100110011100100...

output:

NO

result:

wrong answer Jury found the answer but participant didn't (test case 1)