QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#644155#6109. Similarity Graphstrlen_s_WA 1ms3844kbC++172.9kb2024-10-16 11:24:132024-10-16 11:24:14

Judging History

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

  • [2024-10-16 11:24:14]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3844kb
  • [2024-10-16 11:24:13]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=105,M=5005;
int mp[N][N];
int id[N][N],cnt;
int cx[M],cy[M],col[M];
int f[M<<1];
vector<int>G[M];
int ansp[N],ansq[N];
int n;
int find(int x){return f[x]==x?x:f[x]=find(f[x]);}
bool iscon(int x,int y){return find(x)==find(y);}
bool merge(int x,int y){
  x=find(x),y=find(y);
  if(x==y)return 0;
  f[x]=y;return 1;
}
signed main(){
  ios::sync_with_stdio(0);
  cin.tie(0),cout.tie(0);
  cin>>n;
  for(int i=1;i<=n;i++)
    for(int j=1;j<=n;j++)
      cin>>mp[i][j];
  for(int i=1;i<=n;i++)
    for(int j=i+1;j<=n;j++)
      id[i][j]=++cnt,cx[cnt]=i,cy[cnt]=j;
  for(int i=1;i<=cnt+cnt;i++)f[i]=i;
  for(int i=1;i<=n;i++)
    for(int j=i+1;j<=n;j++)
      for(int k=j+1;k<=n;k++){
        if((mp[i][j]&&mp[j][k]&&mp[i][k])||(!mp[i][j]&&!mp[j][k]&&!mp[i][k]))continue;
        if((mp[i][j]&&mp[i][k])||(!mp[i][j]&&!mp[i][k])){
          if(iscon(id[i][j],id[i][k]+cnt)){cout<<"NO\n";return 0;}
          merge(id[i][j],id[i][k]),merge(id[i][j]+cnt,id[i][k]+cnt);
        }
        if((mp[i][j]&&mp[j][k])||(!mp[i][j]&&!mp[j][k])){
          if(iscon(id[i][j],id[j][k])){cout<<"NO\n";return 0;}
          merge(id[i][j],id[j][k]+cnt),merge(id[i][j]+cnt,id[j][k]);
        }
        if((mp[i][k]&&mp[j][k])||(!mp[i][k]&&!mp[j][k])){
          if(iscon(id[i][k],id[j][k]+cnt)){cout<<"NO\n";return 0;}
          merge(id[i][k],id[j][k]),merge(id[i][k]+cnt,id[j][k]+cnt);
        }
      }
  bool fl=1;
  while(fl){
    fl=0;
    for(int i=1;i<=n;i++)
      for(int j=i+1;j<=n;j++)
        for(int k=j+1;k<=n;k++){
          if(!((mp[i][j]&&mp[j][k]&&mp[i][k])||(!mp[i][j]&&!mp[j][k]&&!mp[i][k])))continue;
          if(iscon(id[i][j],id[i][k]+cnt)){
            if(iscon(id[i][j],id[j][k])){cout<<"NO\n";return 0;}
            fl|=merge(id[i][j],id[j][k]+cnt),fl|=merge(id[i][j]+cnt,id[j][k]);
          }
          if(iscon(id[i][j],id[j][k])){
            if(iscon(id[i][k],id[j][k]+cnt)){cout<<"NO\n";return 0;}
            fl|=merge(id[i][k],id[j][k]),fl|=merge(id[i][k]+cnt,id[j][k]+cnt);
          }
          if(iscon(id[i][k],id[j][k]+cnt)){
            if(iscon(id[i][j],id[i][k]+cnt)){cout<<"NO\n";return 0;}
            fl|=merge(id[i][j],id[i][k]),fl|=merge(id[i][j]+cnt,id[i][k]+cnt);
          }
        }
  }
  for(int i=1;i<=n;i++)ansp[i]=ansq[i]=1;
  for(int i=1;i<=cnt;i++){
    if(!col[i])col[i]=1;
    for(int j=i+1;j<=cnt;j++){
      if(col[j])continue;
      if(iscon(i,j))col[j]=col[i];
      if(iscon(i,j+cnt))col[j]=3-col[i];
    }
    if(!mp[cx[i]][cy[i]]){
      if(col[i]==1)ansp[cx[i]]++,ansq[cy[i]]++;
      else ansp[cy[i]]++,ansq[cx[i]]++;
    }
    else{
      if(col[i]==1)ansp[cx[i]]++,ansq[cx[i]]++;
      else ansp[cy[i]]++,ansq[cx[i]]++;
    }
  }
  cout<<"YES\n";
  for(int i=1;i<=n;i++)cout<<ansp[i]<<' ';cout<<'\n';
  for(int i=1;i<=n;i++)cout<<ansq[i]<<' ';cout<<'\n';
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 1ms
memory: 3780kb

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: 3700kb

input:

1
0

output:

YES
1 
1 

result:

ok ok

Test #4:

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

input:

2
0 0
0 0

output:

YES
2 1 
1 2 

result:

ok ok

Test #5:

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

input:

2
0 1
1 0

output:

YES
2 1 
2 1 

result:

ok ok

Test #6:

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

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: 3724kb

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: 0
Accepted
time: 0ms
memory: 3784kb

input:

3
0 0 1
0 0 0
1 0 0

output:

YES
3 1 2 
2 3 1 

result:

ok ok

Test #9:

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

input:

3
0 0 1
0 0 1
1 1 0

output:

YES
3 2 1 
2 3 1 

result:

ok ok

Test #10:

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

input:

3
0 1 0
1 0 0
0 0 0

output:

YES
3 2 1 
2 1 3 

result:

ok ok

Test #11:

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

input:

3
0 1 0
1 0 1
0 1 0

output:

YES
3 1 2 
2 2 2 

result:

wrong answer Q is not a permutation