cf916CJamie and Interesting Graph
Posted luoyibujue
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了cf916CJamie and Interesting Graph相关的知识,希望对你有一定的参考价值。
/* 构造题就要找到一些特殊信息来做 最小生成树总和质数, 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 << " "; int zz = inf; for(int i = 1; i < n - 1; i ++) { cout << i << " " << i + 1 << " " << "1" << " "; st.insert(make_pair(i, i + 1)); zz--; } cout << n - 1 << " " << n << " " << zz << " "; 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 << " "; break; } } } return 0; }
以上是关于cf916CJamie and Interesting Graph的主要内容,如果未能解决你的问题,请参考以下文章
CF916C Jamie and Interesting Graph
Codeforces Round #457 (Div. 2) CJamie and Interesting Graph
Codeforces 916C - Jamie and Interesting Graph
Jamie and Binary Sequence (changed after round) - CodeForces 916B
CodeForces-916B-Jamie and Binary Sequence(changed after round)(构造)