QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#788689#6502. Disjoint Set UnionOIer_kzcCompile Error//C++203.4kb2024-11-27 17:54:212024-11-27 17:54:26

Judging History

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

  • [2024-11-27 17:54:26]
  • 评测
  • [2024-11-27 17:54:21]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define dbg(x) cerr<<"In Line "<<__LINE__<<' '<<#x<<" = "<<(x)<<endl
int f[1005],g[1005],fa[1005],dag[1005],deg[1005],n;
bool yes[1005],to[1005][1005];
vector<int> v[1005];
#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 18, stdin), p1 == p2) ? EOF : *p1++)
inline ll read() {
	ll x = 0, f = 1;
	char ch = getchar();
	while(ch < '0' || ch > '9') f = ((ch == '-') ? -1 : f), ch = getchar();
	while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
	return x * f;
}
#define eb emplace_back
int find(int x){
    while(x^f[x]) x=f[x];
    return x;
}
int gind(int x){
    while(x^g[x]) x=g[x];
    return x;
}
bool check(){
    for(int i=1;i<=n;i++) if(f[i]==g[i]) return 1;return 0;
}
struct node{
    int t,x,y;
}q[2000005];
bool is[1005],del[1005];
int main(){
    int t=read();
    while(t--){
        n=read();
        for(int i=1;i<=n;i++){
            yes[i]=deg[i]=0;
            for(int j=1;j<=n;j++) to[i][j]=0;
        }
        for(int i=1;i<=n;i++) f[i]=read(),yes[i]=f[i]==i;
        bool no=0;
        for(int i=1;i<=n;i++){
            g[i]=read();
            if(g[i]==i&&!yes[g[i]]&&!no){
                cout<<"NO\n",no=1;
            }
        }
        if(no) continue;
        for(int i=1;i<=n;i++) if(f[i]^g[i]&&!yes[g[i]]){
            cout<<"NO\n",no=1;break;
        }
        if(no) continue;
        for(int i=1;i<=n;i++) if(f[i]^g[i]){
            fa[i]=find(f[i]);
            if(fa[i]^g[i]&&!to[fa[i]][g[i]]) to[fa[i]][g[i]]=1,deg[g[i]]++;
        }
        for(int i=1;i<=n;i++) v[i].clear();
        for(int i=1;i<=n;i++) if(f[i]==i) v[gind(i)].eb(i);
        int tot=0;
        for(int i=1;i<=n;i++) if(g[i]==i){
            queue<int> qu;
            for(int i=1;i<=n;i++) is[i]=0;
            for(int j:v[i]){
                is[j]=1;
                if(!deg[j]) qu.emplace(j);
            }
            int tim=0;
            while(!qu.empty()){
                int f=qu.front();qu.pop();
                if(!is[f]){
                    cout<<"NO\n",no=1;break;
                }
                if(yes[f]) dag[++tim]=f;
                for(int i=1;i<=n;i++) if(to[f][i]){
                    to[f][i]=0;
                    if(!--deg[i]) qu.emplace(i);
                }
            }
            if(no) break;
            for(int j:v[i]) if(deg[j]){
                cout<<"NO\n",no=1;break;
            }
            if(no) break;
            for(int i=1;i<=tim;i++){
                int x=dag[i];
                for(int j=1;j<=n;j++) del[j]=0;
                for(int j=1;j<=n;j++) if(!del[j]&&x^j&&fa[j]==x&&f[j]^g[j]){
                    int now=j;
                    while(now^x){
                        int tmp=f[now];
                        f[now]=x,now=tmp;
                        del[now]=1;
                    }
                    q[++tot]={1,j};
                }
                if(i^tim) f[x]=dag[i+1],q[++tot]={2,x,dag[i+1]};
                for(int j=1;j<=n;j++) if(f[j]==x&&x^g[j]&&x^j) q[++tot]={1,j},fa[j]=dag[i+1];
            }
        }
        if(!no){
            if(check()){
                cout<<"YES\n"<<tot<<endl;
                for(int i=1;i<=tot;i++){
                    cout<<q[i].t<<' '<<q[i].x;
                    if(q[i].t==2) cout<<' '<<q[i].y;cout<<endl;
                }
            }
            else cout<<"NO\n";
        }
    }
}

Details

answer.code:9:8: error: ‘ll’ does not name a type
    9 | inline ll read() {
      |        ^~
answer.code: In function ‘int main()’:
answer.code:33:15: error: too few arguments to function ‘ssize_t read(int, void*, size_t)’
   33 |     int t=read();
      |           ~~~~^~
In file included from /usr/include/unistd.h:1166,
                 from /usr/include/c++/13/bits/atomic_wait.h:44,
                 from /usr/include/c++/13/bits/atomic_base.h:42,
                 from /usr/include/c++/13/bits/shared_ptr_atomic.h:33,
                 from /usr/include/c++/13/memory:81,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:56,
                 from answer.code:1:
/usr/include/x86_64-linux-gnu/bits/unistd.h:34:1: note: declared here
   34 | read (int __fd, void *__buf, size_t __nbytes)
      | ^~~~
answer.code:35:15: error: too few arguments to function ‘ssize_t read(int, void*, size_t)’
   35 |         n=read();
      |           ~~~~^~
/usr/include/x86_64-linux-gnu/bits/unistd.h:34:1: note: declared here
   34 | read (int __fd, void *__buf, size_t __nbytes)
      | ^~~~
answer.code:40:40: error: too few arguments to function ‘ssize_t read(int, void*, size_t)’
   40 |         for(int i=1;i<=n;i++) f[i]=read(),yes[i]=f[i]==i;
      |                                    ~~~~^~
/usr/include/x86_64-linux-gnu/bits/unistd.h:34:1: note: declared here
   34 | read (int __fd, void *__buf, size_t __nbytes)
      | ^~~~
answer.code:43:22: error: too few arguments to function ‘ssize_t read(int, void*, size_t)’
   43 |             g[i]=read();
      |                  ~~~~^~
/usr/include/x86_64-linux-gnu/bits/unistd.h:34:1: note: declared here
   34 | read (int __fd, void *__buf, size_t __nbytes)
      | ^~~~