2017 NEERC J Journey from Petersburg to Moscow (最短路)

题意

给定 n = 1 0 3 , m = 1 0 3 n=10^3,m=10^3 n=103,m=103的图,路径前k大边的和为该路径的代价,问其中所有从 1 − n 1-n 1n的路径中代价的最小值是都少。

题解

  1. 假如所求的最短代价路径的边数小于等于k,那么答案肯定是原图最短路
  2. 假如所求的最短代价路径的边数大于k,那么我们发现其计算的方式是将不在前k大路径的代价置为0去计算。考虑这一问题,我们只要枚举所有边,假设该边为所求最小代价的路径中前k大的最小边,将图中所有边权减去枚举到的边权值(出现负数置0)再跑一遍最短路,结果就是 d i s n + k ⋅ w e i i dis_n+k \cdot wei_i disn+kweii
    证明
    1. 假如枚举到的边比当前边小,那答案必定是 上述计算得到的答案+尾部没被置0的值必定大于上述计算所求
    2. 假如枚举到的边比当前边大,那答案相当于把原来后几位比当前边小的边多加了变成了当前边,答案肯定也会变大。

代码

/**
 *     author:     TelmaZzzz
 *     create:     2019-08-31-15.34.35
**/
#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <ctime>
#include <string>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
//#include <random>
using namespace std;
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/priority_queue.hpp>

using namespace __gnu_pbds;

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
void _R(int &x) { scanf("%d", &x); }
void _R(ll &x) { scanf("%lld", &x); }
void _R(db &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
void _W(const int &x) { printf("%d", x); }
void _W(const ll &x) { printf("%lld", x); }
void _W(const db &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#define rep(x,y,z) for(int x=y;x<=z;x++)
#define erp(x,y,z) for(int x=y;x>=z;x--)
#define PB push_back
#define MP make_pair
#define INF 1073741824
#define inf 1152921504606846976
#define pi 3.14159265358979323846
//#pragma comment(linker,"/STACK:10240000,10240000")
//mt19937 rand_(time(0));
const int N=3007,M=1e5+7;
const long long mod=1e9+7;
inline int read(){int ret=0;char ch=getchar();bool f=1;for(;!isdigit(ch);ch=getchar()) f^=!(ch^'-');for(;isdigit(ch);ch=getchar()) ret=(ret<<1)+(ret<<3)+ch-48;return f?ret:-ret;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll ksm(ll a,ll b,ll mod){int ans=1;while(b){if(b&1) ans=(ans*a)%mod;a=(a*a)%mod;b>>=1;}return ans;}
ll inv2(ll a,ll mod){return ksm(a,mod-2,mod);}//逆元
ll wei[M];
int head[N],NEXT[M],ver[M],tot;void link(int u,int v,ll w){ver[++tot]=v;NEXT[tot]=head[u];head[u]=tot;wei[tot]=w;}


struct node{
    int u,v;
    ll w;
}edge[N];
int n,m,k;
ll dis[N];
bool vis[N];
__gnu_pbds::priority_queue<pair<ll,int> >q;
void build(ll x){
    rep(i,1,m){
        wei[i*2]=max(edge[i].w-x,0LL);
        wei[i*2+1]=max(edge[i].w-x,0LL);
    }
}
void dij(){
    rep(i,1,n) dis[i]=inf,vis[i]=false;
    while(q.size())q.pop();
    q.push(MP(0,1));
    dis[1]=0;
    while(q.size()){
        int x=q.top().second;
        q.pop();
        if(x==n) return;
        if(vis[x]) continue;
        vis[x]=true;
        for(int i=head[x];i;i=NEXT[i]){
            int y=ver[i];
            if(dis[y]>dis[x]+wei[i]){
                dis[y]=dis[x]+wei[i];
                q.push(MP(-dis[y],y));
            }
        }
    }
}
int main(){
    //freopen("1.txt","r",stdin);
    //ios::sync_with_stdio(false);
    int u,v;
    ll w;
    R(n,m,k);
    tot=1;
    rep(i,1,m){
        R(edge[i].u,edge[i].v,edge[i].w);
        link(edge[i].u,edge[i].v,edge[i].w);
        link(edge[i].v,edge[i].u,edge[i].w);
    }
    build(0);
    dij();
    ll ans=inf;
    ans=min(ans,dis[n]);
    rep(i,1,m){
        build(edge[i].w);
        dij();
        ans=min(ans,dis[n]+1LL*k*edge[i].w);

    }
    W(ans);
    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}
### Apache SeaTunnel 2.3.8 安装指南 #### 下载地址 用户可以从官方提供的链接下载 Apache SeaTunnel 2.3.8 版本的二进制文件[^1]。具体下载页面位于以下地址: - **下载页**: https://seatunnel.apache.org/download/ #### 配置环境 在安装之前,需确保本地已正确配置 Java 环境以及必要的依赖项。Java 版本建议为 JDK 8 或更高版本。 #### 启动集群服务 完成解压后,可以通过 `seatunnel-cluster.sh` 脚本来启动 SeaTunnel 集群服务。以下是具体的命令示例[^3]: ```bash ./bin/seatunnel-cluster.sh start ``` 如果需要后台运行该进程,则可使用重定向操作符将其放入后台执行: ```bash nohup ./bin/seatunnel-cluster.sh start > sea_tunnel.log 2>&1 & ``` #### 停止集群服务 当不再需要运行 SeaTunnel 集群时,可通过如下脚本停止服务: ```bash ./bin/stop-seatunnel-cluster.sh ``` #### 使用 Docker 运行 (新增特性)2.3.8 版本起,SeaTunnel 提供了官方支持的 Docker 镜像。这使得通过容器化部署变得更为便捷。以下是基于 Docker 的快速启动方式: 1. 拉取最新镜像: ```bash docker pull apache/seatunnel:2.3.8 ``` 2. 启动容器实例: ```bash docker run -d --name seatunnel-container -p 8081:8081 apache/seatunnel:2.3.8 ``` 上述命令会以后台模式启动 SeaTunnel 并映射默认 Web UI 到主机端口 8081 上。 --- ### 示例代码片段:MySQL 数据迁移至 MySQL 下面是一个简单的作业配置案例,展示如何利用 SeaTunnel 将数据从一个 MySQL 表迁移到另一个表中: ```yaml env { execution.parallelism = 1 } source { mysql { url = "jdbc:mysql://localhost:3306/source_db" username = "root" password = "password" table-name = ["table_source"] } } transform {} sink { mysql { url = "jdbc:mysql://localhost:3306/target_db" username = "root" password = "password" table-name = ["table_target"] } } ``` 此 YAML 文件定义了一个完整的 ETL 流程,其中包含源数据库连接参数、目标数据库连接参数及对应的数据表名称。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值