Skip to content

Commit

Permalink
Merge pull request #1154 from maspypy/ch
Browse files Browse the repository at this point in the history
問題追加 彩色多項式
  • Loading branch information
maspypy authored May 29, 2024
2 parents 23b76b9 + 5662722 commit 39fce7d
Show file tree
Hide file tree
Showing 15 changed files with 1,155 additions and 0 deletions.
62 changes: 62 additions & 0 deletions graph/chromatic_polynomial/checker.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// https://github.com/MikeMirzayanov/testlib/blob/master/checkers/wcmp.cpp

// The MIT License (MIT)

// Copyright (c) 2015 Mike Mirzayanov

// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:

// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.

// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

#include "testlib.h"

using namespace std;

int main(int argc, char * argv[])
{
setName("compare sequences of tokens");
registerTestlibCmd(argc, argv);

int n = 0;
string j, p;

while (!ans.seekEof() && !ouf.seekEof())
{
n++;

ans.readWordTo(j);
ouf.readWordTo(p);

if (j != p)
quitf(_wa, "%d%s words differ - expected: '%s', found: '%s'", n, englishEnding(n).c_str(), compress(j).c_str(), compress(p).c_str());
}

if (ans.seekEof() && ouf.seekEof())
{
if (n == 1)
quitf(_ok, "\"%s\"", compress(j).c_str());
else
quitf(_ok, "%d tokens", n);
}
else
{
if (ans.seekEof())
quitf(_wa, "Participant output contains extra tokens");
else
quitf(_wa, "Unexpected EOF in the participants output");
}
}
35 changes: 35 additions & 0 deletions graph/chromatic_polynomial/gen/big.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <iostream>
#include <tuple>
#include "random.h"
#include "../params.h"

using namespace std;

int main(int, char* argv[]) {

long long seed = atoll(argv[1]);
auto gen = Random(seed);

int n = gen.uniform(MAX_N - 3, MAX_N);
int m = gen.uniform(0, n * (n - 1) / 2);

using P = pair<int, int>;
vector<P> edges;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (gen.uniform_bool()) {
edges.push_back({i, j});
} else {
edges.push_back({j, i});
}
}
}
gen.shuffle(edges.begin(), edges.end());
edges.resize(m);

printf("%d %d\n", n, m);
for (int i = 0; i < m; i++) {
printf("%d %d\n", edges[i].first, edges[i].second);
}
return 0;
}
102 changes: 102 additions & 0 deletions graph/chromatic_polynomial/gen/clique_cycle.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#include <iostream>
#include <tuple>
#include "random.h"
#include "../params.h"

/*
4 cases
case 0,1 : n = 4*5
case 2,3 : n = 3*7 ( random 1 removed )
*/

using namespace std;

int main(int, char* argv[]) {

long long seed = atoll(argv[1]);
auto gen = Random(seed);

int n1 = 4;
int n2 = 5; // size of a cycle : an odd number
if(seed / 2 == 1){
n1 = 3;
n2 = 7;
}

int n = n1 * n2;

vector<pair<int,int>> edges;

if(seed % 2 == 0){
for(int c=0; c<n; c+=n1){
// make a clique on i \in [c, c+n1)
for(int a=0; a<n1; a++){
for(int b=0; b<a; b++){
edges.push_back({ c+a, c+b });
}
}
}
// connect cliques like a cycle
for(int c=0; c<n; c+=n1){
int d = (c + n1) % n;
for(int a=0; a<n1; a++){
for(int b=0; b<n1; b++){
edges.push_back({ c+a, d+b });
}
}
}
}
else if(seed % 2 == 1){
for(int c=0; c<n; c+=n1){
// make a clique on i \in [c, c+n1)
for(int a=0; a<n1; a++){
int b = (a+1) % n1;
edges.push_back({ c+a, c+b });
}
}
// connect cliques like a cycle
for(int c=0; c<n; c+=n1){
for(int d=0; d<c; d+=n1){
for(int a=0; a<n1; a++){
for(int b=0; b<n1; b++){
edges.push_back({ c+a, d+b });
}
}
}
}
}

// permute edges
gen.shuffle(edges.begin(), edges.end());
int m = (int)edges.size();

vector<int> perm(n);
for(int i=0; i<n; i++) perm[i] = i;
gen.shuffle(perm.begin(), perm.end());
for(int i=0; i<m; i++){
// flip edges
if(gen.uniform_bool()) swap(edges[i].first, edges[i].second);
// permute vertices
edges[i].first = perm[edges[i].first];
edges[i].second = perm[edges[i].second];
}

n = MAX_N; {
vector<pair<int,int>> edges_filtered;
for(auto e : edges){
if(e.first < n && e.second < n){
edges_filtered.push_back(e);
}
}
swap(edges, edges_filtered);
m = (int)edges.size();
}

printf("%d %d\n", n, m);
for (int i = 0; i < m; i++) {
printf("%d %d\n", edges[i].first, edges[i].second);
}
return 0;
}
8 changes: 8 additions & 0 deletions graph/chromatic_polynomial/gen/example_00.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
5 7
0 1
0 2
0 4
1 3
2 3
2 4
3 4
1 change: 1 addition & 0 deletions graph/chromatic_polynomial/gen/example_01.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
20 0
2 changes: 2 additions & 0 deletions graph/chromatic_polynomial/gen/example_02.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
3 1
2 2
6 changes: 6 additions & 0 deletions graph/chromatic_polynomial/gen/example_03.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
2 5
0 1
1 0
0 1
0 1
1 0
38 changes: 38 additions & 0 deletions graph/chromatic_polynomial/gen/loop.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include <iostream>
#include <tuple>
#include "random.h"
#include "../params.h"

using namespace std;

int main(int, char* argv[]) {
long long seed = atoll(argv[1]);
auto gen = Random(seed);

int n = gen.uniform(MIN_N, MAX_N);
int m = gen.uniform(0, n * (n - 1) / 2);

using P = pair<int, int>;
vector<P> edges;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (gen.uniform_bool()) {
edges.push_back({i, j});
} else {
edges.push_back({j, i});
}
}
}
gen.shuffle(edges.begin(), edges.end());
edges.resize(m);

int k = gen.uniform<int>(0, n - 1);
edges.push_back({k, k});
++m;

printf("%d %d\n", n, m);
for (int i = 0; i < m; i++) {
printf("%d %d\n", edges[i].first, edges[i].second);
}
return 0;
}
34 changes: 34 additions & 0 deletions graph/chromatic_polynomial/gen/multi_edge.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include <iostream>
#include <tuple>
#include "random.h"
#include "../params.h"

using namespace std;

int main(int, char* argv[]) {
long long seed = atoll(argv[1]);
auto gen = Random(seed);

int n = gen.uniform(MIN_N, MAX_N);
int m = gen.uniform<int>(0, MAX_M);

using P = pair<int, int>;
vector<P> edges;
for (int i = 0; i < m; ++i) {
while (1) {
int a = gen.uniform<int>(0, n - 1);
int b = gen.uniform<int>(0, n - 1);

if (seed % 2 == 0 && a == b) continue;

edges.push_back({a, b});
break;
}
}

printf("%d %d\n", n, m);
for (int i = 0; i < m; i++) {
printf("%d %d\n", edges[i].first, edges[i].second);
}
return 0;
}
35 changes: 35 additions & 0 deletions graph/chromatic_polynomial/gen/random.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <iostream>
#include <tuple>
#include "random.h"
#include "../params.h"

using namespace std;

int main(int, char* argv[]) {

long long seed = atoll(argv[1]);
auto gen = Random(seed);

int n = gen.uniform(MIN_N, MAX_N);
int m = gen.uniform(0, n * (n - 1) / 2);

using P = pair<int, int>;
vector<P> edges;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (gen.uniform_bool()) {
edges.push_back({i, j});
} else {
edges.push_back({j, i});
}
}
}
gen.shuffle(edges.begin(), edges.end());
edges.resize(m);

printf("%d %d\n", n, m);
for (int i = 0; i < m; i++) {
printf("%d %d\n", edges[i].first, edges[i].second);
}
return 0;
}
Loading

0 comments on commit 39fce7d

Please sign in to comment.