模板
常用代码框架
/*
Name:
Solution:
By Frather_
*/
#include <iostream>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <stack>
#define ll long long
#define InF 0x7fffffff
#define kMax 10e5
#define kMin -10e5
#define kMod 998244353
#define kMod2 19260817
#define kMod3 19660813
#define base 1331
using namespace std;
/*=========================================快读*/
int read()
{
int x=0,f=1;
char c=getchar();
while(c<'0'||c>'9')
{
if(c=='-')
f=-1;
c=getchar();
}
while(c>='0'&&c<='9')
{
x=(x<<3)+(x<<1)+(c^48);
c=getchar();
}
return x*f;
}
/*=====================================定义变量*/
/*===================================自定义函数*/
/*=======================================主函数*/
int main()
{
return 0;
}
快读
简易快读( \(int\) 型)
int read()
{
int x=0,f=1;
char c=getchar();
while(c<'0'||c>'9')
{
if(c=='-')
f=-1;
c=getchar();
}
while(c>='0'&&c<='9')
{
x=(x<<3)+(x<<1)+(c^48);
c=getchar();
}
return x*f;
}
int main()
{
int n;
n=read();
}
多功能快读
using namespace std;
/*=========================================快读*/
template <typename Temp>
inline void read(Temp &x)
{
Temp f = 1;
char c = getchar();
while (c < '0' || c > '9')
{
if (c == '-')
f = -1;
c = getchar();
}
while (c >= '0' && c <= '9')
{
x = (x * 10) + (c ^ 48);
c = getchar();
}
if (c != '.')
{
x *= f;
return;
}
c = getchar();
Temp base = 0.1;
while(c >= '0' && c <= '9')
{
x += (c ^ '0') * base;
base /= 10;
c = getchar();
}
x *= f;
}
int main()
{
int n;
read(n);
}
比较函数
较大数
int KMax(int a,int b)
{
return a>=b ? a : b;
}
较小数
int KMin(int a,int b)
{
return a<=b ? a : b;
}
数据结构
并查集
优化和判断集合包含关系
int Find(int x)//查询
{
return x==fa[x] ? x :fa[x]=Find(fa[x]);
}
int fa[1000010];
int main()
{
for(int i=1;i<=n;i++)//初始化
fa[i]=i;
}
图论
多源最短路
Floyd
#include <iostream>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <stack>
#define ll long long
#define InF 0x7fffffff
#define kMax 10e5
#define kMin -10e5
#define kMOD 998244353
using namespace std;
/*=========================================快读*/
int read()
{
int x=0,f=1;
char c=getchar();
while(c<'0'||c>'9')
{
if(c=='-')
f=-1;
c=getchar();
}
while(c>='0'&&c<='9')
{
x=(x<<3)+(x<<1)+(c^48);
c=getchar();
}
return x*f;
}
/*=====================================定义变量*/
int n, m, s;
int f[10010][10010];
/*===================================自定义函数*/
void Floyd()
{
for(int i=1;i<=n;i++)
f[i][i]=0;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
for(int k=1;k<=n;k++)
min(f[i][k],f[j][i]+f[i][k]);
}
/*=======================================主函数*/
int main()
{
n=read();
m=read();
s=read();
memset(f,0x3f,sizeof(f));
for(int i=1;i<=n;i++)
{
int from=read();
int to=read();
int dis=read();
min(f[from][to],dis);
}
Floyd();
for(int i=1;i<=m;i++)
printf("%d ",f[s][i]);
return 0;
}