当前位置:网站首页>Codeforces CodeTON Round 2 (Div. 1 + Div. 2, Rated, Prizes!) E
Codeforces CodeTON Round 2 (Div. 1 + Div. 2, Rated, Prizes!) E
2022-08-06 10:05:00 【juraws】
Codeforces CodeTON Round 2 (Div. 1 + Div. 2, Rated, Prizes!)
CodeTON Round 2 (Div. 1 + Div. 2, Rated, Prizes!)
关于想提前下班然后用小号打然后好像还能拿2个虚拟币但懒得领奖这件事
E - Count Seconds
prob.: 给n点m边的DAG,保证有且仅有一个点没有出度,每个点有个点权,每单位时间对于每个点权大于0的点,该点权值-1,所有该点连向的点权值+1,问整个图所有点权值都变成0所需要的时间
ideas: 考虑一个点的点权变化,设点权大于0的状态为1状态,点权为0的状态为0状态,则可能是若干01交替之后一段很长的连续的1然后变成0
考虑出度为0的点什么时候最终变成0
前面01交替的状态比较想不清楚,但由于n其实不是很大,前n单位时间可以暴力计算,然后在此基础上计算对于出度为0的这个点这段为1的状态长度有多少
注意拓扑序遍历,初始化操作以及对于前n单位时间暴力时整个图就已经变成全0的情况
code:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 998244353;
const int N = 1e4 + 10;
ll a[N];
vector<int> g[N], t[N];
ll din[N], cnt[N];
signed main() {
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
int _;
cin >> _;
while (_--) {
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
for (int i = 0; i < m; ++i) {
int x, y;
cin >> x >> y;
g[x].push_back(y);
t[y].push_back(x);
din[y]++;
}
queue<int> que;
int p = -1;
for (int i = 1; i <= n; ++i) {
if (g[i].size() == 0) {
p = i;
}
if (din[i] == 0) que.push(i);
}
vector<int> idx;
while (!que.empty()) {
int tmp = que.front();
que.pop();
idx.push_back(tmp);
for (auto to : g[tmp]) {
din[to]--;
if (din[to] == 0) {
que.push(to);
}
}
}
reverse(idx.begin(), idx.end());
bool done = 1;
for (int tt = 0; tt < n; ++tt) {
done = 1;
for (auto x: idx) {
if (a[x] <= 0) continue;
a[x]--;
done = 0;
for (auto to : g[x]) {
a[to]++;
}
}
if (done) {
cout << tt << endl;
break;
}
}
if (done) {
for (int i = 0; i <= n; ++i) {
g[i].clear();
t[i].clear();
din[i] = cnt[i] = 0;
}
continue;
}
reverse(idx.begin(), idx.end());
for (auto x : idx) {
cnt[x] = (cnt[x] + a[x]) % mod;
for (auto to : g[x]) {
cnt[to] = (cnt[to] + cnt[x]) % mod;
}
}
cout << (n + cnt[p]) % mod << endl;
for (int i = 0; i <= n; ++i) {
g[i].clear();
t[i].clear();
din[i] = cnt[i] = 0;
}
}
}
F
博弈,sg函数,打表
改天一定
边栏推荐
- Kotlin进阶指南 - default constructor not found
- Argo CD Experience
- HMM model
- JDBC database connection
- CMasher极大丰富Matplotlib自带colormaps
- Let's talk about the pits of mysql's unique index, why does it still generate duplicate data?
- 智能三子棋——保姆级教学。
- Web version Xshell supports FTP connection and SFTP connection [Detailed tutorial] Continue from the previous article
- 聊聊mysql唯一索引的哪些坑,为什么还是产生重复数据?
- jupyter notebook & pycharm (anaconda)
猜你喜欢

数据治理(一):为什么要数据治理

【OpenCV】 人脸识别

View the Linux log on the web side, and view the Linux log on the web side

HMM模型

Unity Atlas Optimization Principle

C语言结构体

【 machine learning bayesian classifier

基于FPGA的AHT10传感器温湿度读取

nuxt页面访问速度优化
![Web version Xshell supports FTP connection and SFTP connection [Detailed tutorial] Continue from the previous article](/img/30/c9d087554bb028582c494098664275.png)
Web version Xshell supports FTP connection and SFTP connection [Detailed tutorial] Continue from the previous article
随机推荐
46 most complete Redis interview questions in history, I found all the interviewers asked (with answers)
【机器学习】决策树
Interface automation landing practice
46道史上最全Redis面试题,面试官能问的都被我找到了(含答案)
Vant3——复选框点击其他后格外出现一个输入框
HCIP 18 days notes
Changsha College 2022 Summer Training Competition (1)
水一个心跳动画
Neo4j: Running a Graph Database with Docker and the Cypher Query Language
UE5 使用Mesh Editor 查看骨骼相对于root的坐标系
How is the LinkedList added?
JDBC数据库连接
White, concise and easy company website source WordPress theme 2 or more
nuxt页面访问速度优化
集成学习进阶
USES the stack to determine whether a parenthesis matching
"Introduction to nlp + actual combat: Chapter 9: Recurrent Neural Network"
TCP的重传机制、滑动窗口、流量控制、拥塞控制,这一篇就够了
数据库日增20万条数据,用读写分离和分库分表加持破它
Usage of torch.utils.data in pytorch ---- Loading Data