/*
* @Author: sanjusss
* @Date: 2023-06-09 09:07:23
* @LastEditors: sanjusss
* @LastEditTime: 2023-06-09 16:04:44
* @FilePath: \2000\2600\2690\2699.cpp
*/
#include "leetcode.h"
// 时间复杂度 O(n * log(target) * mlogm)
// class Solution {
// public:
// vector<vector<int>> modifiedGraphEdges(int n, vector<vector<int>>& edges, int source, int destination, int
// target) {
// static constexpr int sc_maxEdge = 1e9;
// vector<unordered_map<int, int>> conns(n);
// vector<int> mods;
// for (int i = 0; i < edges.size(); ++i) {
// auto& e = edges[i];
// if (e[2] < 0) {
// mods.push_back(i);
// }
// else {
// conns[e[0]][e[1]] = e[2];
// conns[e[1]][e[0]] = e[2];
// }
// }
// // 1 表示最短距离大于target
// // 0 表示最短距离等于target
// // -1 表示最短距离小于target
// auto check = [&]() -> int {
// vector<int> dis(n, INT_MAX);
// dis[source] = 0;
// priority_queue<pair<int, int>, vector<pair<int, int>>, greater<>> q;
// q.emplace(0, source);
// while (!q.empty()) {
// auto [cur, i] = q.top();
// q.pop();
// if (dis[i] < cur) {
// continue;
// }
// else if (i == destination) {
// if (cur < target) {
// return -1;
// }
// else if (cur > target) {
// return 1;
// }
// else {
// return 0;
// }
// }
// for (auto [j, d] : conns[i]) {
// if (dis[j] <= cur + d) {
// continue;
// }
// dis[j] = cur + d;
// if (dis[j] > target) {
// continue;
// }
// q.emplace(dis[j], j);
// }
// }
// return 1;
// };
// if (check() < 0) {
// return {};
// }
// for (int i : mods) {
// auto& e = edges[i];
// conns[e[0]][e[1]] = 1;
// conns[e[1]][e[0]] = 1;
// e[2] = 1;
// }
// switch (check()) {
// case 1:
// return {};
// case 0:
// return edges;
// default:
// break;
// }
// for (int i : mods) {
// auto& e = edges[i];
// conns[e[0]][e[1]] = target;
// conns[e[1]][e[0]] = target;
// e[2] = target;
// }
// for (int i : mods) {
// auto& e = edges[i];
// auto& m1 = conns[e[0]][e[1]];
// auto& m2 = conns[e[1]][e[0]];
// auto& m3 = e[2];
// int left = 0;
// int right = target + 1;
// while (left <= right) {
// int mid = (left + right) / 2;
// m1 = mid;
// m2 = mid;
// m3 = mid;
// int res = check();
// if (res == 0) {
// if (mid >= 1 && mid <= target) {
// return edges;
// }
// else {
// break;
// }
// }
// else if (res > 0) {
// right = mid - 1;
// }
// else {
// left = mid + 1;
// }
// }
// m1 = 1;
// m2 = 1;
// m3 = 1;
// }
// return {};
// }
// };
// class Solution {
// public:
// vector<vector<int>> modifiedGraphEdges(int n, vector<vector<int>>& edges, int source, int destination, int
// target) {
// static constexpr int sc_maxEdge = 1e9;
// vector<unordered_map<int, int>> conns(n);
// vector<int> mods;
// for (int i = 0; i < edges.size(); ++i) {
// auto& e = edges[i];
// if (e[2] < 0) {
// mods.push_back(i);
// }
// else {
// conns[e[0]][e[1]] = e[2];
// conns[e[1]][e[0]] = e[2];
// }
// }
// auto check = [&]() -> int {
// vector<int> dis(n, INT_MAX);
// dis[source] = 0;
// priority_queue<pair<int, int>, vector<pair<int, int>>, greater<>> q;
// q.emplace(0, source);
// while (!q.empty()) {
// auto [cur, i] = q.top();
// q.pop();
// if (dis[i] < cur) {
// continue;
// }
// else if (i == destination) {
// return cur;
// }
// for (auto [j, d] : conns[i]) {
// if (dis[j] <= cur + d) {
// continue;
// }
// dis[j] = cur + d;
// q.emplace(dis[j], j);
// }
// }
// return INT_MAX;
// };
// if (check() < target) {
// return {};
// }
// for (int i : mods) {
// auto& e = edges[i];
// conns[e[0]][e[1]] = target;
// conns[e[1]][e[0]] = target;
// e[2] = target;
// }
// if (check() == target) {
// return edges;
// }
// for (int i : mods) {
// auto& e = edges[i];
// auto& m1 = conns[e[0]][e[1]];
// auto& m2 = conns[e[1]][e[0]];
// auto& m3 = e[2];
// m1 = 1;
// m2 = 1;
// m3 = 1;
// int next = check();
// if (next <= target) {
// m3 = (target - next) + 1;
// return edges;
// }
// }
// return {};
// }
// };
// class Solution {
// public:
// vector<vector<int>> modifiedGraphEdges(int n, vector<vector<int>>& edges, int source, int destination, int target) {
// vector<vector<pair<int, int>>> conns(n);
// int m = edges.size();
// for (int i = 0; i < m; ++i) {
// auto& e = edges[i];
// conns[e[0]].emplace_back(e[1], i);
// conns[e[1]].emplace_back(e[0], i);
// }
// vector<int> srcDist(n, INT_MAX);
// priority_queue<pair<int, int>, vector<pair<int, int>>, greater<>> q;
// q.emplace(0, source);
// srcDist[source] = 0;
// while (!q.empty()) {
// auto [d, i] = q.top();
// q.pop();
// if (d > srcDist[i]) {
// continue;
// }
// for (auto [j, ei] : conns[i]) {
// int dj = d + max(edges[ei][2], 1);
// if (dj >= srcDist[j]) {
// continue;
// }
// srcDist[j] = dj;
// q.emplace(dj, j);
// }
// }
// if (srcDist[destination] > target) {
// return {};
// }
// vector<int> desDist(n, INT_MAX);
// q.emplace(0, destination);
// desDist[destination] = 0;
// while (!q.empty()) {
// auto [d, i] = q.top();
// q.pop();
// if (d > desDist[i]) {
// continue;
// }
// for (auto [j, ei] : conns[i]) {
// if (edges[ei][2] == -1) {
// edges[ei][2] = max(target - srcDist[j] - desDist[i], 1);
// }
// int dj = d + edges[ei][2];
//
没有合适的资源?快使用搜索试试~ 我知道了~
我在leetcode上的解题记录。(C++版).zip
![preview](https://csdnimg.cn/release/downloadcmsfe/public/img/white-bg.ca8570fa.png)
共2000个文件
cpp:1529个
hpp:450个
h:16个
![preview-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/scale.ab9e0183.png)
需积分: 1 0 下载量 175 浏览量
2024-03-08
11:19:45
上传
评论
收藏 2.28MB ZIP 举报
温馨提示
我在leetcode上的解题记录。(C++版).zip
资源推荐
资源详情
资源评论
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![txt](https://img-home.csdnimg.cn/images/20210720083642.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
收起资源包目录
![package](https://csdnimg.cn/release/downloadcmsfe/public/img/package.f3fc750b.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
![avatar-default](https://csdnimg.cn/release/downloadcmsfe/public/img/lazyLogo2.1882d7f4.png)
![avatar](https://profile-avatar.csdnimg.cn/7523b5f53972472bbc02153c09b3a5e5_2301_82214311.jpg!1)
大圣
- 粉丝: 447
- 资源: 152
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
最新资源
- python39.dll
- 【Matlab 六自由度机器人】Fixed Angles(固定角度) 和 Euler Angles(欧拉角) 之间的区别
- BMSP430工程PPT说明书.zip
- FlinkFlinkF
- 《计算机网络-自顶向下方法》答案
- 基于pyqt5框架开发的demo项目 全栈开发,短小精悍,入门学习,上手简单
- 国内IP地址大全 站长资源 访问IP设置 Order allow,deny 使用方法
- 【JavaScript实现点击鼠标出现爱心特效脚本】直接引入index.html文件可用!!!
- OPC Core Components Redistributable (x86).msi
- 一套基于Python的交易量化框架,详细复现步骤
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback-tip](https://img-home.csdnimg.cn/images/20220527035111.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)