QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#421016#1869. Power Station of Artgrass8cowAC ✓266ms57484kbC++171.7kb2024-05-25 09:47:462024-05-25 09:47:47

Judging History

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

  • [2024-05-25 09:47:47]
  • 评测
  • 测评结果:AC
  • 用时:266ms
  • 内存:57484kb
  • [2024-05-25 09:47:46]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int n,m;
#define pb push_back
const int N=1e6+10;
vector<int>g[N];
int p1[N],p2[N],c1[N],c2[N],co[N];
char c[N];
bool ef;
vector<int>V;
void dfs(int x){
    V.pb(x);
    for(int v:g[x]){
        if(!co[v])co[v]=3-co[x],dfs(v);
        else ef|=(co[x]==co[v]);
    }
}
const int Z=1e6+10;
bool sol(){
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)g[i].clear(),co[i]=0;
    for(int i=0,u,v;i<m;i++){
        scanf("%d%d",&u,&v);
        g[u].pb(v),g[v].pb(u);
    }
    for(int i=1;i<=n;i++)scanf("%d",&p1[i]);
    scanf("%s",c+1);for(int i=1;i<=n;i++)c1[i]=(c[i]=='B');
    for(int i=1;i<=n;i++)scanf("%d",&p2[i]);
    scanf("%s",c+1);for(int i=1;i<=n;i++)c2[i]=(c[i]=='B');
    for(int i=1;i<=n;i++)if(!co[i]){
        V.clear(),ef=0,co[i]=1,dfs(i);
        int sz=V.size();
        if(!ef){
            vector<int>t1,t2;
            for(int x:V)
                t1.pb(((co[x]==2)^c1[x])*Z+p1[x]),
                t2.pb(((co[x]==2)^c2[x])*Z+p2[x]);
            sort(t1.begin(),t1.end()),sort(t2.begin(),t2.end());
            bool fuc=1;
            for(int i=0;i<sz;i++)fuc&=(t1[i]==t2[i]);
            if(!fuc)return 0;
        }
        else{
            int ce=0;
            for(int x:V)ce+=c1[x],ce-=c2[x];
            if(ce&1)return 0;
            else{
                ce/=2;
                vector<int>t1,t2;
                for(int x:V)t1.pb(p1[x]),t2.pb(p2[x]);
                sort(t1.begin(),t1.end()),sort(t2.begin(),t2.end());
                bool fuc=1;for(int i=0;i<sz;i++)fuc&=(t1[i]==t2[i]);
                if(!fuc)return 0;
            }
        }
    }
    return 1;
}
int main(){
    int T;scanf("%d",&T);while(T--)puts(sol()?"YES":"NO");
    return 0;
}

詳細信息

Test #1:

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

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: 266ms
memory: 57484kb

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