QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#399519 | #1869. Power Station of Art | ship2077 | AC ✓ | 250ms | 52572kb | C++14 | 1.4kb | 2024-04-26 14:17:53 | 2024-04-26 14:17:53 |
Judging History
answer
#include<bits/stdc++.h>
#define fir first
#define sec second
using namespace std;
constexpr int M=1e6+5;
vector<int>adj[M],vec;
int n,m,col[M];string str;
bool fl,flag;pair<int,int>a1[M],a2[M];
void dfs(int x,int c){
col[x]=c;vec.push_back(x);
for (auto y:adj[x])
if (!~col[y]) dfs(y,!c);
else if (col[x]==col[y])
flag=0;
}
void solve(){ cin>>n>>m;
for (int i=1;i<=n;i++) adj[i].clear(),col[i]=-1;
for (int i=1;i<=m;i++){
int x,y;cin>>x>>y;
adj[x].push_back(y);
adj[y].push_back(x);
} fl=1;
for (int i=1;i<=n;i++) cin>>a1[i].fir;
cin>>str;str=" "+str;
for (int i=1;i<=n;i++) a1[i].sec=str[i]=='R';
for (int i=1;i<=n;i++) cin>>a2[i].fir;
cin>>str;str=" "+str;
for (int i=1;i<=n;i++) a2[i].sec=str[i]=='R';
for (int i=1;i<=n&&fl;i++)
if (!~col[i]){ int cnt=0;
vec.clear();flag=1;dfs(i,0);
for (auto x:vec)
if (flag) a1[x].sec^=col[x],a2[x].sec^=col[x];
else cnt+=a1[x].sec-a2[x].sec,a1[x].sec=a2[x].sec=0;
if (cnt&1) fl=0;
vector<pair<int,int>>tmp1,tmp2;
for (auto x:vec)
tmp1.push_back(a1[x]),
tmp2.push_back(a2[x]);
sort(tmp1.begin(),tmp1.end());
sort(tmp2.begin(),tmp2.end());
for (int i=0;fl&&i<tmp1.size();i++)
if (tmp1[i]!=tmp2[i])
{fl=0;break;}
}
puts(fl?"YES":"NO");
}
int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int T;cin>>T;while (T--) solve();return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 33312kb
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: 250ms
memory: 52572kb
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