QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#621922 | #1869. Power Station of Art | 369Pai | RE | 0ms | 0kb | C++20 | 1.8kb | 2024-10-08 18:23:05 | 2024-10-08 18:23:06 |
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e6 + 5;
int n , m , a[N] , c[N] , b[N] , d[N];
int ta[N] , tb[N] , col[N];
vector<int>g[N] , id;
bool Dfs(int u , int c)
{
bool ok = 1;
col[u] = c;
id.push_back(u);
for(int v : g[u])
{
if(!col[v])ok &= Dfs(v , 3 - c);
else if(c == col[v])ok = 0;
}
return ok;
}
int Solve()
{
cin >> n >> m;
for(int i = 1 ; i <= n ; i++)g[i].clear();
for(int i = 1 ; i <= m ; i++)
{
int u , v; cin >> u >> v;
g[u].push_back(v);
g[v].push_back(u);
}
for(int i = 1 ; i <= n ; i++)
cin >> a[i];
string s; cin >> s;
for(int i = 1 ; i <= n ; i++)
c[i] = s[i - 1] == 'B';
for(int i = 1 ; i <= n ; i++)
cin >> b[i];
cin >> s;
for(int i = 1 ; i <= n ; i++)
d[i] = s[i - 1] == 'B';
for(int i = 1 ; i <= n ; i++)col[i] = 0;
for(int i = 1 ; i <= n ; i++)
if(!col[i])
{
id.clear();
bool is2 = Dfs(i , 1);
if(is2)
{
set<int>sa , sb;
for(int i : id)
{
sa.insert(((col[i] == 1) ^ c[i] ? 1 : -1) * a[i]);
sb.insert(((col[i] == 1) ^ d[i] ? 1 : -1) * b[i]);
}
if(sa != sb)
{
cout << "NO\n";
return 0;
}
}
else
{
int dt = 0;
set<int>sa , sb;
// cerr << "id:";
// for(int i : id)cerr << i << ',';
// cerr << "\n";
for(int i : id)
{
sa.insert(a[i]);
sb.insert(b[i]);
if(c[i])dt++;
if(d[i])dt--;
}
// cerr << dt << " (" << (sa == sb) << ")\n";
if((dt % 2) || sa != sb)
{
cout << "NO\n";
return 0;
}
}
}
cout << "YES\n";
return 0;
}
signed main()
{
freopen("graph.in" , "r" , stdin);
freopen("graph.out" , "w" , stdout);
ios::sync_with_stdio(0);
cin.tie(0) , cout.tie(0);
int T; cin >> T;
while(T--)Solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Dangerous Syscalls
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