当前位置:网站首页>两日总结九
两日总结九
2022-08-11 01:14:00 【JSU-YSJ】
总结时间:2022/8/2~8/3
打比赛总结:航电杯6
主要是补题补了一个图论题目,想法十分牛,就是建立一个外点来作为中转站,替代了原来要建立的n*n/2条边,十分可以,就是在补题目的过程中,那个分层的数组开在里面每次都是卡我,卡的老火了!!!!
后面总算是过了。
#include <bits/stdc++.h>
using namespace std;
#define OST ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define endl "\n"
#define pair pair<int, int>
#define ll long long
const int N = 1e6 + 1;
const ll inf = 0x3f3f3f3f3f3f3f3f;
struct node {
int x;
ll v;
bool friend operator<(node x1, node x2) { return x1.v > x2.v; }
};
vector<node> e[3 * N];
// vector<int> dep[N];
int dp[N];
ll low[3 * N];
bool vis[3 * N];
int n, s, t, k, p, point, ceng;
priority_queue<node> q;
// void dfs(int fa, int u, int cnt) {
// if (vis[u]) return;
// vis[u] = 1;
// ceng = max(ceng, cnt);
// dep[cnt].push_back(u);
// for (auto v : e[u]) {
// if (v.x != fa) { dfs(u, v.x, cnt + 1); }
// }
// }
void dfs1(int fa, int u) {
dp[u] = dp[fa] + 1;
ceng = max(ceng, dp[u]);
for (auto v : e[u]) {
if (v.x != fa) { dfs1(u, v.x); }
}
}
void init() {
point = 0;
ceng = 0;
for (int i = 0; i < 3 * N; i++) {
e[i].clear();
low[i] = inf;
vis[i] = 0;
}
}
void Dij() {
// memset(vis, 0, sizeof(vis));
// priority_queue<node> q;
while (!q.empty()) q.pop();
q.push({s, 0});
low[s] = 0;
vis[s] = 1;
while (!q.empty()) {
auto now = q.top();
q.pop();
for (auto x : e[now.x]) {
if (low[x.x] > low[now.x] + x.v) {
low[x.x] = low[now.x] + x.v;
if (!vis[x.x]) {
q.push({x.x, low[x.x]});
vis[x.x] = 1;
}
}
}
}
cout << low[t] << endl;
}
void solve() {
init();
cin >> n;
for (int i = 1; i < n; i++) {
int u, v, z;
cin >> u >> v >> z;
e[u].push_back({v, z}), e[v].push_back({u, z});
}
dp[0] = -1;
dfs1(0, 1);
cin >> k >> p;
// vector<int> dep[ceng + 1];
// for (int i = 1; i <= n; i++) { dep[dp[i]].push_back(i); }
// for (int i = 1; i <= ceng; i++) {
// cout << i << "**";
// for (auto x : dep[i]) { cout << x << " "; }
// cout << endl;
// }
// cout << ceng << endl;
// for (int i = 1; i <= ceng; i++) {
// point += 2;
// for (auto x : dep[i]) {
// e[x].push_back({n + (point - 1), 0});
// e[x].push_back({n + (point), 0});
// }
// if (i - k >= 1) {
// for (auto x : dep[i - k]) { e[n + point - 1].push_back({x, p}); }
// }
// if (i + k <= ceng) {
// for (auto x : dep[i + k]) { e[n + point].push_back({x, p}); }
// }
// if (i - k - 1 > 0) dep[i - k - 1].clear();
// // dep[i].clear();
// }
for (int i = 1; i <= n; i++) {
if (dp[i] != 0) { e[i].push_back({n + 2 * dp[i] - 1, p}); }
if (dp[i] != ceng) { e[i].push_back({n + 2 * (dp[i] + 1), p}); }
if (dp[i] + k <= ceng) { e[n + 2 * (dp[i] + k) - 1].push_back({i, 0}); }
if (dp[i] - k >= 0) { e[n + 2 * (dp[i] - k + 1)].push_back({i, 0}); }
}
cin >> s >> t;
Dij();
}
int main() {
OST;
int T;
cin >> T;
while (T--) { solve(); }
return 0;
}
然后是就是其他的刷题:
基本都是1600分的题目,主要是练练思维能力,还有题目的切入点、。
然后就是一场DIV3CF:
然后就是请假了 。。
边栏推荐
- 两个链表的第一个公共节点——LeetCode
- HW-常见攻击方式和漏洞原理(2)
- Elastic scaling of construction resources
- R language multiple linear regression, ARIMA analysis of the impact of different candidates in the United States on the economic GDP time series
- How to easily obtain the citation format of references?
- 构建资源的弹性伸缩
- WinForm(五)控件和它的成员
- 微信小程序获取当前页面的url和参数
- 微信小程序自定义navigationBar
- 循环单词
猜你喜欢
Single-chip human-computer interaction--matrix key
apache+PHP+MySQL+word press, page error when installing word press?
3d打印出现stl文件物体不是流形,意味着不是水密体...解决办法
HW-蓝队工作流程(1)
微信小程序通过URL Scheme动态的渲染数据
WinForm (5) control and its members
【Video】Report Sharing | 2021 Insurance Industry Digital Insights
[GXYCTF2019]BabySQli
Distributed. Performance optimization
Apache Commons Configuration远程代码执行漏洞(CVE-2022-33980)分析&复现
随机推荐
编程技巧│selenium 更新 chromedriver 驱动
20张图,全面掌握MVCC原理!
Summarize the acquisition of commonly used file information QFileInfo in Qt: suffix, name, path, link
Successfully resolved TypeError: can't multiply sequence by non-int of type 'float'
WebView2 通过 PuppeteerSharp 实现RPA获取壁纸 (案例版)
[GXYCTF2019]BabySQli
More parameter exposure of Pico 4: Pancake + color perspective, and Pro version
SystemVerilog: 验证知识点点滴滴
两个链表的第一个公共节点——LeetCode
分库分表ShardingSphere-JDBC笔记整理
16. 最接近的三数之和
报考PMP需要做些什么准备?
两个数组的交集
2022.8.10-----leetcode.640
postgresql parameter meaning
C#-委托的详细用法
Single-chip human-computer interaction--matrix key
QT+VTK+PCL拟合圆柱并计算起始点、中止点
HCIP-R&S By Wakin自用笔记(3)OSPF之引入外部路由、Forwarding-Address、汇总、特殊区域
EN 12467纤维水泥平板产品—CE认证