QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#63537#1869. Power Station of ArtlmeowdnAC ✓429ms221628kbC++172.3kb2022-11-22 15:54:192022-11-22 15:54:20

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-11-22 15:54:20]
  • 评测
  • 测评结果:AC
  • 用时:429ms
  • 内存:221628kb
  • [2022-11-22 15:54:19]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define eb emplace_back
#define y1 yylyylyylyyl
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vp;
typedef unsigned long long ull;
typedef __int128 lll;
 
long long read() {
    long long res=0, w=1; char c=getchar();
    while(!isdigit(c)) {if(c=='-') w=-1; c=getchar();}
    while(isdigit(c)) {res=res*10+c-48, c=getchar();}
    return res*w;
}

const int N=1e6+9;
int T,n,m,col[N],sz[N],cnt,bp[N],a[N],b[N],bx[N],by[N];
vi e[N],s[N],sx[N],sy[N];
vp gx[N],gy[N];
char t[N];

void dfs(int u,int c,int id) {
    col[u]=c, s[id].eb(u), sz[id]++;
    for(auto v:e[u]) {
        if(col[v]!=-1) {
            if(col[u]==col[v]) bp[id]=0;
        } else dfs(v,c^1,id);
    } 
}

signed main() {
    T=read();
    while(T--) {
        n=read(), m=read();
        rep(i,1,n) col[i]=-1;
        rep(i,1,m) {
            int u=read(), v=read();
            e[u].eb(v), e[v].eb(u);
        }
        rep(i,1,n) if(col[i]==-1) bp[++cnt]=1, dfs(i,0,cnt);

        rep(i,1,n) a[i]=read();
        scanf("%s",t+1);
        rep(i,1,n) b[i]=(t[i]=='B');
        rep(i,1,cnt) {
            for(auto x:s[i]) sx[i].eb(a[x]), bx[i]^=b[x];
            sort(sx[i].begin(),sx[i].end());
            if(bp[i]) {
                for(auto x:s[i]) gx[i].eb(pii(a[x],b[x]^col[x]));
                sort(gx[i].begin(),gx[i].end());    
            }
        }

        rep(i,1,n) a[i]=read();
        scanf("%s",t+1);
        rep(i,1,n) b[i]=(t[i]=='B');
        rep(i,1,cnt) {
            for(auto x:s[i]) sy[i].eb(a[x]), by[i]^=b[x];
            sort(sy[i].begin(),sy[i].end());
            if(bp[i]) {
                for(auto x:s[i]) gy[i].eb(pii(a[x],b[x]^col[x]));
                sort(gy[i].begin(),gy[i].end());
            }
        }

        bool ans=1;
        rep(i,1,cnt) ans&=((sx[i]==sy[i])&(bx[i]==by[i])&(gx[i]==gy[i]));
        if(ans) puts("YES");
        else puts("NO");

        rep(i,1,n) e[i].clear(), col[i]=-1, a[i]=b[i]=0;
        rep(i,1,cnt) sz[i]=bp[i]=bx[i]=by[i]=0;
        rep(i,1,cnt) s[i].clear(), sx[i].clear(), sy[i].clear(), gx[i].clear(), gy[i].clear();
        cnt=0;
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 36ms
memory: 155540kb

input:

3
2 1
1 2
3 4
RR
4 3
BB
3 2
1 2
2 3
1 1 1
RBR
1 1 1
BBB
3 3
1 2
2 3
3 1
1 1 1
RBR
1 1 1
BBB

output:

YES
NO
YES

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 429ms
memory: 221628kb

input:

25054
5 10
4 5
4 2
4 3
4 1
5 2
5 3
5 1
2 3
2 1
3 1
12 2 9 10 7
RRRBB
10 2 9 7 12
RRBRB
1 0
4
R
4
R
8 4
4 3
1 5
8 5
6 5
7 2 11 10 9 6 3 5
RBRBBRBR
7 2 10 11 6 5 3 9
RBRBBRBR
7 4
7 2
5 1
5 6
5 4
12 5 9 14 5 12 12
RRBRBRR
14 12 9 5 12 12 5
RBBRBRB
10 1
4 6
5 3 2 9 7 3 11 11 6 8
RRRBRRBBBR
5 3 2 3 7 9 1...

output:

YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
YES
NO
YES
NO
NO
YES
YES
YES
NO
YES
NO
YES
YES
NO
YES
YES
NO
YES
NO
YES
YES
YES
YES
NO
YES
YES
NO
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
NO
YES
NO
YES
YES
YES
YES
NO
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
YES
YES
YES
NO
YES
NO
NO...

result:

ok 25054 lines