当前位置:网站首页>2022 Nioke Summer Multi-School Training Camp 1 J Serval and Essay
2022 Nioke Summer Multi-School Training Camp 1 J Serval and Essay
2022-07-30 22:55:00 【_Kiwi_Berry_】
题意:
给一个图,for each point in the graph,if and only if all of its incoming edges are true,This point is true.Start can specify a point to be true,Ask the maximum number of true points
思路:
A starting point that is likely to maximize the result
1.当一个点V1的父节点V2只有一个时,select parent nodeV2作为起始点,若V2的父节点V3只有一个时,则选V3,Until a node has more than one parent or is0,Set it as the starting point
2.当存在环时,Pick any point on the ring as the starting point
for all points that satisfy the condition,Simulate a topological sort,Take the maximum value as the result,It can be proved that each point is traversed no more than 10次,So the complexity can be controlled at1e8内
Code
#include <bits/stdc++.h>
// #define debug freopen("_in.txt", "r", stdin);
#define debug freopen("_in.txt", "r", stdin), freopen("_out.txt", "w", stdout);
typedef long long ll;
typedef unsigned long long ull;
typedef struct Node *bintree;
using namespace std;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll maxn = 1e6 + 10;
const ll maxm = 2e6 + 10;
const ll mod = 1e9 + 7;
const double pi = acos(-1);
const double eps = 1e-8;
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1 | 1
ll T, n, m, q, d,kase=0;
string str, str1;
vector<ll> to[maxn], vec;
map<ll, ll> mp;
ll fa[maxn], tag[maxn], ind[maxn], tmp[maxn];
queue<ll> que, que1;
void solve()
{
scanf("%lld", &n);
for (ll i = 1; i <= n; i++)
{
to[i].clear();
tag[i]=0;
}
while (!que.empty())
{
que.pop();
}
for (ll i = 1; i <= n; i++)
{
scanf("%lld", &m);
ind[i] = m;
for (ll j = 1; j <= m; j++)
{
ll x;
scanf("%lld", &x);
fa[i] = x;
to[x].push_back(i);
}
if (m == 1)
{
tag[fa[i]] = 1;
que.push(fa[i]);
}
else
{
fa[i] = 0;
}
}
for (ll i = 1; i <= n; i++)
{
tmp[i] = ind[i];
}
ll ans = 1;
while (!que.empty())
{
ll temp = que.front();
que.pop();
if (!tag[temp])
continue;
tag[temp] = 0;
ll now = temp;
while (tag[fa[temp]] > 0)
{
if (fa[temp] == now)
{
break;
}
temp = fa[temp];
tag[temp] = 0;
}
vec.clear();
mp.clear();
while (!que1.empty())
que1.pop();
que1.push(temp);
vec.push_back(temp);
mp[temp] = 1;
tmp[temp] = 0;
ll res = 1;
while (!que1.empty())
{
ll x = que1.front();
que1.pop();
for (auto y : to[x])
{
if (mp[y] == 0)
{
mp[y] = 1;
vec.push_back(y);
}
tmp[y]--;
if (tmp[y] == 0)
{
que1.push(y);
res++;
tag[y] = 0;
}
}
}
ans = max(ans, res);
for (auto x : vec)
{
tmp[x] = ind[x];
}
}
printf("Case #%lld: %lld\n",++kase, ans);
}
signed main()
{
// debug;
scanf("%lld", &T);
// T = 1;
while (T--)
{
solve();
}
}
边栏推荐
- The most complete Redis basic + advanced project combat summary notes in history
- 只会纯硬件,让我有点慌
- 力扣题(3)—— 无重复字符的最长子串
- 2021GDCPC广东省大学生程序设计竞赛 B.Byfibonacci
- CISP-PTE Zhenti Demonstration
- Ningbo Zhongning Pawn will transfer 29.5% of the equity for 2.8338 million yuan, and the owner's equity in 2021 will be 9.6875 million yuan
- cmd (command line) to operate or connect to the mysql database, and to create databases and tables
- Collapse legacy apps
- [MySQL] Mysql transaction and authority management
- The Road to Ad Monetization for Uni-app Mini Program Apps: Rewarded Video Ads
猜你喜欢
# Dasctf 7月赋能赛 WP
Difference between cookie and session
The most complete Redis basic + advanced project combat summary notes in history
WSL2设置默认启动用户(debian)
Alibaba Cloud video on demand + project combat
482-静态库、动态库的制作、使用及区别
[MySQL] Mysql transaction and authority management
Golang go-redis cluster模式下不断创建新连接,效率下降问题解决
Py之pdpbox:pdpbox的简介、安装、案例应用之详细攻略
ML's shap: Based on FIFA 2018 Statistics (2018 Russia World Cup) team match star classification prediction data set using RF random forest + calculating SHAP value single-sample force map/dependency c
随机推荐
Apache Doris系列之:深入认识实时分析型数据库Apache Doris
win10重建索引
WSL安装图形界面并通过xrdp/X-Launch访问
proxy反向代理
打动中产精英群体,全新红旗H5用产品力跑赢需求
ZZULIOJ:1119: 数列有序
cmd (command line) to operate or connect to the mysql database, and to create databases and tables
PS基础学习(一)
Py之pdpbox:pdpbox的简介、安装、案例应用之详细攻略
Successfully resolved ModuleNotFoundError: No module named 'Image'
ZZULIOJ:1120: 最值交换
The Road to Ad Monetization for Uni-app Mini Program Apps: Rewarded Video Ads
IDEA使用技巧
cnpm installation steps
matlab标量场作图
2022.7.28
反转链表-就地逆置法
Mysql进阶优化篇01——四万字详解数据库性能分析工具(深入、全面、详细,收藏备用)
Excel basic study notes
QT开发简介、命名规范、signal&slot信号槽