当前位置:网站首页>CF1634E Fair Share
CF1634E Fair Share
2022-07-05 05:31:00 【solemntee】
The question : Yes m m m An array , The number of numbers in each array is even . Divide each array in half to the set A 、 B A、B A、B Make the final resettable same, judge whether it is legal, and give the scheme .
First of all, I probably only think of Euler circuit on the court , But because there is no demolition point to build a map , We can only do the case of non re set , Later, I had no choice but to broadcast .
The method is to create a bipartite map , Left m m m Dots represent each array , Right c n t cnt cnt( Number of digital categories ) A little bit .
Numbers from the left to the right i i i The directed edge of represents i i i among A A A aggregate , On the contrary, it means to give B B B aggregate . It is easy to know that the original problem is equivalent to searching Euler circuits on bipartite graphs .
Then because there is no need to output the path , Just dye the edges with black and white , Then keep searching the ring .
Then finding a ring will not affect the Euler circuit property of the complementary graph , It is also obvious that Euler can definitely search a ring , That's it .
By the way, please enjoy the new one l a m b d a lambda lambda function
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
int m;
scanf("%d",&m);
vector<vector<int>>a(m+1),ans(m+1);
map<int,int>mp,cnt;
int asdf=0;
for(int i=1;i<=m;i++)
{
int n;
scanf("%d",&n);
a[i].resize(n+1);
ans[i].resize(n+1,-1);
for(int j=1;j<=n;j++)
{
scanf("%d",&a[i][j]);
if(mp[a[i][j]]==0)mp[a[i][j]]=++asdf;
cnt[mp[a[i][j]]]++;
}
}
for(int i=1;i<=asdf;i++)if(cnt[i]%2==1)
{
printf("NO");
return 0;
}
vector<vector<pair<int,int>>>gra(4e5+5);
vector<int>cur(4e5+5);
const int MX=2e5;
for(int i=1;i<=m;i++)
{
for(int j=1;j<a[i].size();j++)
{
gra[i].push_back({
mp[a[i][j]]+MX,j});
gra[MX+mp[a[i][j]]].push_back({
i,j});
cur[i]++;
cur[MX+mp[a[i][j]]]++;
}
}
function<void(int,int)>dfs=[&](int now,int flag)
{
int u=now;
while(cur[u])
{
cur[u]--;
auto [to,pos]=gra[u][cur[u]];
while(ans[min(u,to)][pos]<0)
{
ans[min(u,to)][pos]=flag;
dfs(to,1-flag);
}
}
};
for(int i=1;i<=m;i++)dfs(i,0);
printf("YES\n");
for(int i=1;i<=m;i++)
{
for(int j=1;j<ans[i].size();j++)
{
if(ans[i][j]==0)printf("L");
else printf("R");
}
printf("\n");
}
return 0;
}
边栏推荐
- Talking about JVM (frequent interview)
- Codeforces Round #716 (Div. 2) D. Cut and Stick
- Corridor and bridge distribution (csp-s-2021-t1) popular problem solution
- 剑指 Offer 53 - I. 在排序数组中查找数字 I
- Sword finger offer 06 Print linked list from beginning to end
- Graduation project of game mall
- [to be continued] [depth first search] 547 Number of provinces
- Detailed explanation of expression (csp-j 2021 expr) topic
- Haut OJ 1350: choice sends candy
- lxml.etree.XMLSyntaxError: Opening and ending tag mismatch: meta line 6 and head, line 8, column 8
猜你喜欢
Sword finger offer 06 Print linked list from beginning to end
Fragment addition failed error lookup
剑指 Offer 06.从头到尾打印链表
Web APIs DOM node
[speed pointer] 142 circular linked list II
YOLOv5-Shufflenetv2
Acwing 4300. Two operations
Romance of programmers on Valentine's Day
To be continued] [UE4 notes] L4 object editing
Sword finger offer 05 Replace spaces
随机推荐
Detailed explanation of expression (csp-j 2021 expr) topic
Developing desktop applications with electron
Sword finger offer 58 - ii Rotate string left
sync.Mutex源码解读
Daily question - longest substring without repeated characters
质量体系建设之路的分分合合
Romance of programmers on Valentine's Day
剑指 Offer 53 - I. 在排序数组中查找数字 I
Software test -- 0 sequence
Find a good teaching video for Solon framework test (Solon, lightweight application development framework)
Haut OJ 1350: choice sends candy
PMP candidates, please check the precautions for PMP examination in July
[to be continued] [depth first search] 547 Number of provinces
lxml.etree.XMLSyntaxError: Opening and ending tag mismatch: meta line 6 and head, line 8, column 8
C language Essay 1
Graduation project of game mall
A preliminary study of sdei - see the essence through transactions
卷积神经网络——卷积层
[speed pointer] 142 circular linked list II
记录QT内存泄漏的一种问题和解决方案