当前位置:网站首页>[diary of supplementary questions] [2022 Niuke summer school 1] j-serval and essay
[diary of supplementary questions] [2022 Niuke summer school 1] j-serval and essay
2022-07-24 02:24:00 【cls1277】
Pro
https://ac.nowcoder.com/acm/contest/33186/J
Sol
If a dot can be dyed , If and only if only one incoming edge is connected to the point . Therefore, if the penetration is 1 Points of are pre queued , Update the connected nodes in a topology like manner , Update the queue at the same time , And maintain all spots that can be dyed black at the same time with the union search set .
It can be found that the final joint search set is formed with f a [ i ] = i fa[i]=i fa[i]=i A forest of trees with roots , The same tree can be dyed at the same time , The answer is the maximum size of trees in the forest .
Niuke's machine is still unstable , So the following code adds a bit of something that is often stuck
Code
//By cls1277
#include<bits/stdc++.h>
using namespace std;
typedef int LL;
#define Fo(i,a,b) for(LL i=(a); i<=(b); i++)
#define Ro(i,b,a) for(LL i=(b); i>=(a); i--)
#define Eo(i,x,_) for(LL i=head[x]; i; i=_[i].next)
#define Ms(a,b) memset((a),(b),sizeof(a))
#define endl '\n'
const LL maxn = 2e5+5;
LL n, fa[maxn];
inline LL read() {
LL x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9') {
if(ch=='-') f=-1; ch=getchar(); }
while(ch>='0'&&ch<='9') {
x=(x<<1)+(x<<3)+(ch^48); ch=getchar(); }
return x*f;
}
LL find(LL x) {
while(x!=fa[x]) x = fa[x] = fa[fa[x]];
return x;
}
unordered_set<LL> e[maxn], pre[maxn];
int main() {
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
#ifdef DEBUG
freopen("data.txt","r",stdin);
#endif
LL t; t=read(); //cin>>t;
Fo(tt,1,t) {
// cin>>n;
n = read();
vector<LL> sz(n+1, 1);
vector<bool> vis(n+1, 0);
// unordered_map<LL, unordered_set<LL>> e, pre;
Fo(i,1,n) {
e[i].clear();
pre[i].clear();
}
Fo(i,1,n) {
fa[i] = i;
LL x; x=read(); //cin>>x;
Fo(j,1,x) {
LL y; y=read(); //cin>>y;
e[y].insert(i);
pre[i].insert(y);
}
}
// queue<LL> q;
vector<LL> q(n+1, 0);
LL _h=0, _t=-1;
Fo(i,1,n)
if(pre[i].size()==1) {
// q.push(i);
q[++_t] = i;
vis[i] = 1;
}
while(_h<=_t) {
// while(!q.empty()) {
// LL u = q.front(); q.pop();
LL u = q[_h++];
LL p = *pre[u].begin();
// for(auto it:pre[u]) {
// p = it;
// break;
// }
LL p1=find(u), p2=find(p);
if(p1==p2) continue;
if(sz[p1]>sz[p2]) swap(p1, p2);
fa[p1] = p2;
sz[p2] += sz[p1];
for(auto it:e[p1]) {
e[p2].insert(it);
pre[it].erase(p1);
pre[it].insert(p2);
if(pre[it].size()==1&&!vis[it]) {
vis[it] = 1;
// q.push(it);
q[++_t] = it;
}
}
}
LL ans = 1;
Fo(i,1,n) ans = max(ans, sz[i]);
// cout<<"Case #"<<tt<<": "<<ans<<endl;
printf("Case #%lld: %lld\n", tt, ans) ;
}
return 0;
}
边栏推荐
- BPG notes (III)
- Pbootcms template calls the tag ordinal number from 2 or automatic number
- 毕业设计校园信息发布平台网站源码
- 2022-07-22: what is the output of the following go language code? A:1; B:1.5; C: Compilation error; D:1.49。 package main import “fmt“ func main() { var i
- regular expression
- LeetCode 70爬楼梯、199二叉树的右视图、232用栈实现队列、143重排链表
- 小散量化炒股记|基于多任务爬虫技术, 实现A股实时行情Level1采样
- Jmeter+influxdb+grafana pressure measurement real-time monitoring platform construction
- Leetcode 203. remove linked list elements (2022.07.22)
- 以科技传递温度,vivo守护生物多样性之美
猜你喜欢

LoadRunner12安装、录制第一个脚本以及代理服务器没有响应解决

Responsive pbootcms template decoration design website

Tdengine helps Siemens' lightweight digital solution simicas simplify data processing process

Writing of graph nodes that trigger different special effects during the day and at night in Tiktok

Is software testing still popular in 2022?

Resumption: a deck of cards (54), three people fighting the landlord, what is the probability that the big and small kings are in the same family

How to do a good job of accompanying translation

以科技传递温度,vivo守护生物多样性之美

Canvas drawing (mouse click to draw and lift to end)

奔走相告,行情与量化页面功能优化!股票量化分析工具QTYX-V2.4.5
随机推荐
【补题日记】[2022牛客暑期多校1]D-Mocha and Railgun
NetApp FAS系列一个CIFS bug引起的控制器重启案例分享
Is software testing still popular in 2022?
ASP. Net core write a cache attribute tool
Crud operation of mongodb (2)
View Binding 混淆问题。我两天都在研究混淆。
[Luogu] p1318 ponding area
wallys/WiFi6 MiniPCIe Module 2T2R2 × 2.4GHz 2x5GHz MT7915 MT7975
pbootcms模板调用标签序数从2开始或者自动数开始
无需编码,自动实现“异步 Request-Reply”模式
【补题日记】[2022牛客暑期多校1]J-Serval and Essay
文心大模型扬起新“帆”,产业应用大潮已至
5年接觸近百比特老板,身為獵頭的我,發現昇職的秘密不過4個字
One year after graduation, I gave up the internship opportunity and taught myself software testing at home. The internship of my classmates has just ended. I have become a 12K monthly salary testing e
奔走相告,行情与量化页面功能优化!股票量化分析工具QTYX-V2.4.5
【数据集】——flyingthings3d光流部分数据集下载
以科技传递温度,vivo守护生物多样性之美
Crop leaf disease identification system
Opensmile introduction and problems encountered during installation
C - structure