QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#63533 | #1869. Power Station of Art | lmeowdn | TL | 12ms | 151304kb | C++17 | 2.2kb | 2022-11-22 15:40:55 | 2022-11-22 15:40:58 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
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],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,m) {
int u=read(), v=read();
e[u].eb(v), e[v].eb(u);
}
rep(i,1,n) if(col[i]==-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(b[x]^col[x]);
}
}
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(b[x]^col[x]);
}
}
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();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 12ms
memory: 151304kb
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: -100
Time Limit Exceeded
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 NO YES YES YES YES YES YES NO YES NO YES NO NO YES YES YES NO YES YES YES YES NO YES YES NO YES NO YES YES YES YES YES YES YES NO YES YES YES YES YES YES YES YES YES YES YES YES YES YES NO YES 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 ...