Submission #242233


Source Code Expand

Copy
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <queue>

#pragma warning( disable: 4996 )

using namespace std;

typedef long long ll;

#define INF 1000000000
#define EPS 1e-10

#define MAX_N 10
#define MAX_M 20

int N, M;
int c[MAX_N];
int edge[MAX_N][MAX_N];

int a[MAX_M];
int b[MAX_M];
int r[MAX_M];

int d[MAX_N][MAX_N];

bool city[MAX_N];

bool check(int s, int S){
	
	if (city[s])
		return true;

	for (int i = 0; i < N; i++){
		if (d[s][i] == 1 && !(S >> i & 1)){
			if (check(i, S | 1 << s)){
				return true;
			}
		}
	}

	return false;

}

int main() {

	cin >> N >> M;
	if (N > 8 || M > 10)
		return 0;

	for (int i = 0; i < N; i++){
		cin >> c[i];
	}

	for (int i = 0; i < M; i++){
		cin >> a[i] >> b[i] >> r[i];
		a[i]--;
		b[i]--;
	}

	int ans = INF;
	int num = N + M;

	for (int i = 0; i < 1 << num; i++){
		
		memset(d, 0, sizeof(d));
		fill(city, city + N, false);

		int tmp = 0;
		for (int j = 0; j < num; j++){
			if (j < N){
				if (i >> j & 1){
					city[j] = true;
					tmp += c[j];
				}
			}
			else{
				if (i >> j & 1){
					d[a[j - N]][b[j - N]] = d[b[j - N]][a[j - N]] = 1;
					tmp += r[j - N];
				}
			}
		}

		bool flag = true;

		for (int i = 0; i < N; i++){
			if (!check(i, 0)){
				flag = false;
				break;
			}
		}

		if (flag){
			ans = min(ans, tmp);
		}

	}

	cout << ans << endl;

	return 0;
}

Submission Info

Submission Time
Task C - 高橋君と国家
User taketake0609
Language C++ (G++ 4.6.4)
Score 0
Code Size 1820 Byte
Status
Exec Time 110 ms
Memory 920 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 subtask0-sample-01.txt, subtask0-sample-02.txt, subtask0-sample-03.txt
Subtask1 0 / 10 subtask0-sample-01.txt, subtask0-sample-02.txt, subtask0-sample-03.txt, subtask1-01.txt, subtask1-02.txt, subtask1-03.txt, subtask1-04.txt, subtask1-05.txt, subtask1-06.txt, subtask1-07.txt, subtask1-08.txt, subtask1-09.txt, subtask1-10.txt, subtask1-11.txt, subtask1-12.txt, subtask1-13.txt, subtask1-14.txt, subtask1-15.txt, subtask1-16.txt, subtask1-17.txt, subtask1-18.txt, subtask1-19.txt, subtask1-20.txt, subtask1-21.txt, subtask1-22.txt, subtask1-23.txt, subtask1-24.txt, subtask1-25.txt, subtask1-26.txt, subtask1-27.txt, subtask1-28.txt, subtask1-29.txt, subtask1-30.txt
Subtask2 0 / 20 subtask0-sample-01.txt, subtask0-sample-02.txt, subtask0-sample-03.txt, subtask1-01.txt, subtask1-02.txt, subtask1-03.txt, subtask1-04.txt, subtask1-05.txt, subtask1-06.txt, subtask1-07.txt, subtask1-08.txt, subtask1-09.txt, subtask1-10.txt, subtask1-11.txt, subtask1-12.txt, subtask1-13.txt, subtask1-14.txt, subtask1-15.txt, subtask1-16.txt, subtask1-17.txt, subtask1-18.txt, subtask1-19.txt, subtask1-20.txt, subtask1-21.txt, subtask1-22.txt, subtask1-23.txt, subtask1-24.txt, subtask1-25.txt, subtask1-26.txt, subtask1-27.txt, subtask1-28.txt, subtask1-29.txt, subtask1-30.txt, subtask2-01.txt, subtask2-02.txt, subtask2-03.txt, subtask2-04.txt, subtask2-05.txt, subtask2-06.txt, subtask2-07.txt, subtask2-08.txt, subtask2-09.txt, subtask2-10.txt, subtask2-11.txt, subtask2-12.txt, subtask2-13.txt, subtask2-14.txt, subtask2-15.txt, subtask2-16.txt, subtask2-17.txt, subtask2-18.txt, subtask2-19.txt, subtask2-20.txt, subtask2-21.txt, subtask2-22.txt, subtask2-23.txt, subtask2-24.txt, subtask2-25.txt, subtask2-26.txt, subtask2-27.txt, subtask2-28.txt, subtask2-29.txt, subtask2-30.txt
Subtask3 0 / 30 subtask0-sample-01.txt, subtask0-sample-02.txt, subtask0-sample-03.txt, subtask1-01.txt, subtask1-02.txt, subtask1-03.txt, subtask1-04.txt, subtask1-05.txt, subtask1-06.txt, subtask1-07.txt, subtask1-08.txt, subtask1-09.txt, subtask1-10.txt, subtask1-11.txt, subtask1-12.txt, subtask1-13.txt, subtask1-14.txt, subtask1-15.txt, subtask1-16.txt, subtask1-17.txt, subtask1-18.txt, subtask1-19.txt, subtask1-20.txt, subtask1-21.txt, subtask1-22.txt, subtask1-23.txt, subtask1-24.txt, subtask1-25.txt, subtask1-26.txt, subtask1-27.txt, subtask1-28.txt, subtask1-29.txt, subtask1-30.txt, subtask2-01.txt, subtask2-02.txt, subtask2-03.txt, subtask2-04.txt, subtask2-05.txt, subtask2-06.txt, subtask2-07.txt, subtask2-08.txt, subtask2-09.txt, subtask2-10.txt, subtask2-11.txt, subtask2-12.txt, subtask2-13.txt, subtask2-14.txt, subtask2-15.txt, subtask2-16.txt, subtask2-17.txt, subtask2-18.txt, subtask2-19.txt, subtask2-20.txt, subtask2-21.txt, subtask2-22.txt, subtask2-23.txt, subtask2-24.txt, subtask2-25.txt, subtask2-26.txt, subtask2-27.txt, subtask2-28.txt, subtask2-29.txt, subtask2-30.txt, subtask3-01.txt, subtask3-02.txt, subtask3-03.txt, subtask3-04.txt, subtask3-05.txt, subtask3-06.txt, subtask3-07.txt, subtask3-08.txt, subtask3-09.txt, subtask3-10.txt, subtask3-11.txt, subtask3-12.txt, subtask3-13.txt, subtask3-14.txt, subtask3-15.txt, subtask3-16.txt, subtask3-17.txt, subtask3-18.txt, subtask3-19.txt, subtask3-20.txt, subtask3-21.txt, subtask3-22.txt, subtask3-23.txt, subtask3-24.txt, subtask3-25.txt, subtask3-26.txt, subtask3-27.txt, subtask3-28.txt, subtask3-29.txt, subtask3-30.txt
Subtask4 0 / 40 subtask0-sample-01.txt, subtask0-sample-02.txt, subtask0-sample-03.txt, subtask1-01.txt, subtask1-02.txt, subtask1-03.txt, subtask1-04.txt, subtask1-05.txt, subtask1-06.txt, subtask1-07.txt, subtask1-08.txt, subtask1-09.txt, subtask1-10.txt, subtask1-11.txt, subtask1-12.txt, subtask1-13.txt, subtask1-14.txt, subtask1-15.txt, subtask1-16.txt, subtask1-17.txt, subtask1-18.txt, subtask1-19.txt, subtask1-20.txt, subtask1-21.txt, subtask1-22.txt, subtask1-23.txt, subtask1-24.txt, subtask1-25.txt, subtask1-26.txt, subtask1-27.txt, subtask1-28.txt, subtask1-29.txt, subtask1-30.txt, subtask2-01.txt, subtask2-02.txt, subtask2-03.txt, subtask2-04.txt, subtask2-05.txt, subtask2-06.txt, subtask2-07.txt, subtask2-08.txt, subtask2-09.txt, subtask2-10.txt, subtask2-11.txt, subtask2-12.txt, subtask2-13.txt, subtask2-14.txt, subtask2-15.txt, subtask2-16.txt, subtask2-17.txt, subtask2-18.txt, subtask2-19.txt, subtask2-20.txt, subtask2-21.txt, subtask2-22.txt, subtask2-23.txt, subtask2-24.txt, subtask2-25.txt, subtask2-26.txt, subtask2-27.txt, subtask2-28.txt, subtask2-29.txt, subtask2-30.txt, subtask3-01.txt, subtask3-02.txt, subtask3-03.txt, subtask3-04.txt, subtask3-05.txt, subtask3-06.txt, subtask3-07.txt, subtask3-08.txt, subtask3-09.txt, subtask3-10.txt, subtask3-11.txt, subtask3-12.txt, subtask3-13.txt, subtask3-14.txt, subtask3-15.txt, subtask3-16.txt, subtask3-17.txt, subtask3-18.txt, subtask3-19.txt, subtask3-20.txt, subtask3-21.txt, subtask3-22.txt, subtask3-23.txt, subtask3-24.txt, subtask3-25.txt, subtask3-26.txt, subtask3-27.txt, subtask3-28.txt, subtask3-29.txt, subtask3-30.txt, subtask4-01.txt, subtask4-02.txt, subtask4-03.txt, subtask4-04.txt, subtask4-05.txt, subtask4-06.txt, subtask4-07.txt, subtask4-08.txt, subtask4-09.txt, subtask4-10.txt, subtask4-11.txt, subtask4-12.txt, subtask4-13.txt, subtask4-14.txt, subtask4-15.txt, subtask4-16.txt, subtask4-17.txt, subtask4-18.txt, subtask4-19.txt, subtask4-20.txt, subtask4-21.txt, subtask4-22.txt, subtask4-23.txt, subtask4-24.txt, subtask4-25.txt, subtask4-26.txt, subtask4-27.txt, subtask4-28.txt, subtask4-29.txt, subtask4-30.txt
Case Name Status Exec Time Memory
subtask0-sample-01.txt 34 ms 672 KB
subtask0-sample-02.txt 25 ms 800 KB
subtask0-sample-03.txt 26 ms 668 KB
subtask1-01.txt 26 ms 796 KB
subtask1-02.txt 26 ms 676 KB
subtask1-03.txt 27 ms 800 KB
subtask1-04.txt 25 ms 804 KB
subtask1-05.txt 27 ms 676 KB
subtask1-06.txt 25 ms 672 KB
subtask1-07.txt 25 ms 800 KB
subtask1-08.txt 25 ms 804 KB
subtask1-09.txt 35 ms 672 KB
subtask1-10.txt 43 ms 804 KB
subtask1-11.txt 51 ms 756 KB
subtask1-12.txt 46 ms 804 KB
subtask1-13.txt 26 ms 704 KB
subtask1-14.txt 29 ms 800 KB
subtask1-15.txt 30 ms 804 KB
subtask1-16.txt 64 ms 668 KB
subtask1-17.txt 65 ms 796 KB
subtask1-18.txt 24 ms 796 KB
subtask1-19.txt 43 ms 800 KB
subtask1-20.txt 110 ms 792 KB
subtask1-21.txt 105 ms 800 KB
subtask1-22.txt 103 ms 796 KB
subtask1-23.txt 107 ms 800 KB
subtask1-24.txt 105 ms 800 KB
subtask1-25.txt 104 ms 796 KB
subtask1-26.txt 105 ms 800 KB
subtask1-27.txt 107 ms 712 KB
subtask1-28.txt 105 ms 804 KB
subtask1-29.txt 104 ms 732 KB
subtask1-30.txt 104 ms 800 KB
subtask2-01.txt 25 ms 796 KB
subtask2-02.txt 24 ms 672 KB
subtask2-03.txt 24 ms 796 KB
subtask2-04.txt 25 ms 796 KB
subtask2-05.txt 25 ms 796 KB
subtask2-06.txt 25 ms 796 KB
subtask2-07.txt 25 ms 800 KB
subtask2-08.txt 24 ms 804 KB
subtask2-09.txt 25 ms 796 KB
subtask2-10.txt 25 ms 800 KB
subtask2-11.txt 24 ms 796 KB
subtask2-12.txt 25 ms 800 KB
subtask2-13.txt 26 ms 804 KB
subtask2-14.txt 25 ms 672 KB
subtask2-15.txt 26 ms 668 KB
subtask2-16.txt 25 ms 804 KB
subtask2-17.txt 26 ms 792 KB
subtask2-18.txt 25 ms 672 KB
subtask2-19.txt 24 ms 800 KB
subtask2-20.txt 25 ms 800 KB
subtask2-21.txt 25 ms 796 KB
subtask2-22.txt 26 ms 796 KB
subtask2-23.txt 25 ms 672 KB
subtask2-24.txt 25 ms 804 KB
subtask2-25.txt 25 ms 672 KB
subtask2-26.txt 24 ms 804 KB
subtask2-27.txt 26 ms 796 KB
subtask2-28.txt 25 ms 668 KB
subtask2-29.txt 25 ms 672 KB
subtask2-30.txt 25 ms 672 KB
subtask3-01.txt 25 ms 672 KB
subtask3-02.txt 26 ms 720 KB
subtask3-03.txt 26 ms 800 KB
subtask3-04.txt 24 ms 800 KB
subtask3-05.txt 25 ms 800 KB
subtask3-06.txt 25 ms 800 KB
subtask3-07.txt 26 ms 668 KB
subtask3-08.txt 25 ms 800 KB
subtask3-09.txt 25 ms 668 KB
subtask3-10.txt 25 ms 672 KB
subtask3-11.txt 25 ms 796 KB
subtask3-12.txt 26 ms 708 KB
subtask3-13.txt 23 ms 796 KB
subtask3-14.txt 23 ms 700 KB
subtask3-15.txt 24 ms 804 KB
subtask3-16.txt 24 ms 800 KB
subtask3-17.txt 25 ms 796 KB
subtask3-18.txt 25 ms 800 KB
subtask3-19.txt 24 ms 804 KB
subtask3-20.txt 25 ms 796 KB
subtask3-21.txt 25 ms 676 KB
subtask3-22.txt 24 ms 792 KB
subtask3-23.txt 25 ms 804 KB
subtask3-24.txt 25 ms 800 KB
subtask3-25.txt 24 ms 796 KB
subtask3-26.txt 27 ms 732 KB
subtask3-27.txt 24 ms 792 KB
subtask3-28.txt 24 ms 796 KB
subtask3-29.txt 25 ms 792 KB
subtask3-30.txt 25 ms 712 KB
subtask4-01.txt 24 ms 804 KB
subtask4-02.txt 25 ms 792 KB
subtask4-03.txt 24 ms 796 KB
subtask4-04.txt 25 ms 800 KB
subtask4-05.txt 25 ms 796 KB
subtask4-06.txt 26 ms 920 KB
subtask4-07.txt 26 ms 800 KB
subtask4-08.txt 24 ms 800 KB
subtask4-09.txt 25 ms 796 KB
subtask4-10.txt 26 ms 740 KB
subtask4-11.txt 25 ms 700 KB
subtask4-12.txt 27 ms 792 KB
subtask4-13.txt 26 ms 668 KB
subtask4-14.txt 27 ms 664 KB
subtask4-15.txt 27 ms 676 KB
subtask4-16.txt 27 ms 792 KB
subtask4-17.txt 27 ms 676 KB
subtask4-18.txt 27 ms 736 KB
subtask4-19.txt 27 ms 800 KB
subtask4-20.txt 27 ms 796 KB
subtask4-21.txt 27 ms 804 KB
subtask4-22.txt 26 ms 796 KB
subtask4-23.txt 31 ms 792 KB
subtask4-24.txt 25 ms 676 KB
subtask4-25.txt 33 ms 916 KB
subtask4-26.txt 39 ms 736 KB
subtask4-27.txt 38 ms 756 KB
subtask4-28.txt 36 ms 732 KB
subtask4-29.txt 30 ms 748 KB
subtask4-30.txt 29 ms 736 KB