日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

51nod 3 * problem

發布時間:2025/5/22 编程问答 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 51nod 3 * problem 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1640
題意:
一張無向圖
在最小化最大邊后求最大邊權和
Slove:
sort
最小生成樹
倒敘最大生成樹

#include <iostream> #include <cstdio> #include <algorithm> #include <cmath> #include <cstring> #include <string>using namespace std;#define LL long long#define gc getchar() inline int read() {int x = 0, f = 1; char c = gc; while(c < '0' || c > '9') {if(c == '-') f = -1; c = gc;} while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = gc; return x * f;} inline LL read_LL() {LL x = 0; char c = gc; while(c < '0' || c > '9') c = gc; while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = gc; return x;} #undef gcconst int N = 1e5 + 10;int fa[N]; int A[N << 1], U[N << 1], V[N << 1], W[N << 1]; int n, m;bool Cmp(int a, int b) {return W[a] < W[b];}int Get(int x) {return fa[x] == x ? x : fa[x] = Get(fa[x]);}void Minst(int &R) {for(int i = 1; i <= n; i ++) fa[i] = i;int js = 0;for(int i = 1; i <= m; i ++) {int fu = Get(U[A[i]]), fv = Get(V[A[i]]);if(fu != fv) {fa[fu] = fv;js ++;}if(js == n - 1) {R = i;while(W[A[R + 1]] == W[A[i]]) R ++;return ;}} }inline long long Maxst(int R) {for(int i = 1; i <= n; i ++) fa[i] = i;int js = 0;long long ret = 0;for(int i = R; i >= 1; i --) {int fu = Get(U[A[i]]), fv = Get(V[A[i]]);if(fu != fv) {fa[fu] = fv;ret += W[A[i]];js ++;}if(js == n - 1) return ret;} }int main() {n = read(), m = read();for(int i = 1; i <= m; i ++) A[i] = i, U[i] = read(), V[i] = read(), W[i] = read();sort(A + 1, A + m + 1, Cmp);int R;Minst(R);cout << Maxst(R);return 0; }

1649
由于 1 - n 之間一定存在一種直接相連的道路
判斷哪種直接相連
跑另外一種的最短路

#include <iostream> #include <cstdio> #include <algorithm> #include <cmath> #include <cstring> #include <string>using namespace std;#define LL long long#define gc getchar() inline int read() {int x = 0; char c = gc; while(c < '0' || c > '9') c = gc; while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = gc; return x;} inline LL read_LL() {LL x = 0; char c = gc; while(c < '0' || c > '9') c = gc; while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = gc; return x;} #undef gcconst int N = 410, oo = 999999999;int Map[N][N], Bmap[N][N]; int n, m;int main() {n = read(), m = read();for(int i = 1; i <= n; i ++) for(int j = 1; j <= n; j ++) Map[i][j] = oo;for(int i = 1; i <= n; i ++) Map[i][i] = 0;for(int i = 1; i <= n; i ++) for(int j = 1; j <= n; j ++) Bmap[i][j] = oo;for(int i = 1; i <= n; i ++) Bmap[i][i] = 0;for(int i = 1; i <= m; i ++) {int u = read(), v = read();Map[u][v] = Map[v][u] = 1;}if(Map[1][n] == 1) {for(int i = 1; i <= n; i ++) for(int j = 1; j <= n; j ++) {if(i == j) continue;if(Map[i][j] == oo) Bmap[i][j] = 1;}for(int k = 1; k <= n; k ++)for(int i = 1; i <= n; i ++)for(int j = 1; j <= n; j ++)Bmap[i][j] = min(Bmap[i][j], Bmap[i][k] + Bmap[k][j]);if(Bmap[1][n] == oo) cout << -1;else cout << Bmap[1][n];} else {for(int k = 1; k <= n; k ++)for(int i = 1; i <= n; i ++)for(int j = 1; j <= n; j ++)Map[i][j] = min(Map[i][j], Map[i][k] + Map[k][j]);if(Map[1][n] == oo) cout << -1;else cout << Map[1][n];}return 0; }

1535
圖是樹的充要條件
$m = n - 1$ && 圖聯通
由于題目無自環
所以不存在二元環
并且若 $m >= n - 1$
則圖聯通
此時若 $m = n$
那么就會存在且只存在一個三元環(或更大)
因此只需判斷 $n = m$ 即可

if(n == m) cout << "FHTAGN!"; else cout << "NO";

?

轉載于:https://www.cnblogs.com/shandongs1/p/9591918.html

總結

以上是生活随笔為你收集整理的51nod 3 * problem的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。