标签:pac 最短路 #define 生成 names wap const 生成树 rest
/* 构造题就要找到一些特殊信息来做 最小生成树总和质数, 1到n最短路路径和质数 这两个信息我们可以整合成一个信息 最小生成树是1到n的一条链 其他的边随便加上极大值就好了 */ #include<cstdio> #include<algorithm> #include<cstring> #include<queue> #include<set> #include<ctime> #include<iostream> #define M 410 #define ll long long using namespace std; int f[M][M], d[M][M]; const int inf = 998244353; int read() { int nm = 0, f = 1; char c = getchar(); for(; !isdigit(c); c = getchar()) if(c == ‘-‘) f = -1; for(; isdigit(c); c = getchar()) nm = nm * 10 + c -‘0‘; return nm * f; } set<pair<int,int> >st; int main() { srand(time(0)); int n = read(), m = read(); cout << inf << " " << inf << "\n"; int zz = inf; for(int i = 1; i < n - 1; i ++) { cout << i << " " << i + 1 << " " << "1" << "\n"; st.insert(make_pair(i, i + 1)); zz--; } cout << n - 1 << " " << n << " " << zz << "\n"; st.insert(make_pair(n - 1, n)); m -= n - 1; for(int i = 1; i <= m; i++) { while(1) { int vi = rand() % n + 1, vj = rand() % n + 1; if(vi == vj) continue; if(vi > vj)swap(vi, vj); if(st.find(make_pair(vi, vj)) != st.end()) continue; else { st.insert(make_pair(vi, vj)); cout << vi << " " << vj << " " << inf + 1 << "\n"; break; } } } return 0; }
cf916CJamie and Interesting Graph
标签:pac 最短路 #define 生成 names wap const 生成树 rest
原文地址:https://www.cnblogs.com/luoyibujue/p/9241116.html