OI

· · 个人记录

提前招生yyds

OI没有前途的

CSP2020初赛肯定没过于是准备开始好好学OI
于是开了这个每天来写点自己做过的题吧,,
ymj啊,不要再颓废了,再这样下去啊,三年之后很糟糕的啦,体育中考你要爆蛋的啦
好吧从今天开始尽可能做到一周4次写这个吧,CSP2021加油!

20/10/12:

单源最短路径dijkstra
写了道模板才发现自己连dij模板也忘记了,,
不爆蛋也是正常,,

Code:
#include<bits/stdc++.h>
using namespace std;

const int N = 1e5 + 5;

const int M = 2e5 + 5;

const int INF = 0x7fffffff;

int read()
{
    int x = 0, op = 1;
    char ch = getchar();
    while(ch < '0' || ch > '9') {
        if(ch == '-') op = -1;
        ch = getchar();
    }
    while(ch >= '0' && ch <= '9')
    {
        x = x * 10 + (ch - '0');
        ch = getchar();
    }
    return x * op;
}

int n, m, s, cnt;

int head[M], dis[N], vis[N];

struct node{
    int w, k;
    inline bool operator <(const node &x) const
    {
        return w > x. w;
    }
};

priority_queue<node> q; //优先队列

struct edge{
    int w, u, to, next;
}e[M];

inline void add(int u, int v, int w)
{
    e[++cnt]. u = u;
    e[cnt]. to = v;
    e[cnt]. w = w;
    e[cnt]. next = head[u];
    head[u] = cnt;
}

inline void dijkstra()
{
    for(int i = 1; i <= n; ++ i ) dis[i] = INF;
    dis[s] = 0;
    q.push((node) {0, s});//加入队列
    while(!q. empty())
    {
        node x = q. top(); // 取第一个
        q. pop(); // 弹出
        int u = x. k;
        if(!vis[u])
        {
            vis[u] = 1;
            for(int i = head[u]; i; i = e[i]. next)
            {
                int v = e[i]. to; // 下一点
                //cout << v << endl;
                if(dis[v] > dis[u] + e[i]. w) //松弛操作
                {
                    dis[v] = dis[u] + e[i]. w;
                    q.push((node) {dis[v], v}); // 加入优先队列
                }
            }
        }
    }
} 

int main()
{
    n = read(); m = read(); s = read();
    for(int i = 1; i <= m; ++ i )
    {
        int u = read(), v = read(), w = read();
        add(u, v, w); // 加一条u到v长度为w的边
    }
    dijkstra();
    for(int i = 1; i <= n; ++ i )
    if(dis[i] != INF) cout << dis[i] << " ";
                 else cout << "-1 "; //输出s到每个点的距离
    cout << endl;
    return 0;
}
//20201012 dijkstra.cpp By YMJcvjk AC
20/10/13:

好吧这天鸽子了

20/10/14:

邮递员送信 floyd
挺显然的?不过还没用dijkstra写,明天补上去吧,floyd靠C++11和O2水了过去(逃

Code:
#include<bits/stdc++.h>
using namespace std;

const int N = 1e3 + 5;

int n, m;

int f[N][N];

int read()
{
    int x = 0, op = 1;
    char ch = getchar();
    while(ch < '0' || ch > '9') {
        if(ch == '-') op = -1;
        ch = getchar();
    }
    while(ch >= '0' && ch <= '9')
    {
        x = x * 10 + (ch - '0');
        ch = getchar();
    }
    return x * op;
}

int main()
{
    memset(f, 0x3f, sizeof(f));
    n = read(), m = read();
    for(int i = 1; i <= m; ++ i )
    {
        int u = read(), v = read(), w = read();
        f[u][v] = min(f[u][v], w);
    }
    for(int k = 1; k <= n; ++ k )
      for(int i = 1; i <= n; ++ i )
        if(i != k)
          for(int j = 1; j <= n; ++ j )
            if(i != j && k != j)
              f[i][j] = min(f[i][k] + f[k][j], f[i][j]);
    long long ans = 0;
    for(int i = 2; i <= n; ++ i ) 
     ans += (f[i][1] + f[1][i]);
    cout << ans << endl;
    return 0;
}

07/24 在考虑要不要继续更新这个