Submission #44949890
Source Code Expand
#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
using ll=long long;
template<class T,class U> inline bool chmin(T&x,U y){if(x>y){x=y;return true;}return false;}
template<class T,class U> inline bool chmax(T&x,U y){if(x<y){x=y;return true;}return false;}
void solve(){
int n, m;
cin >> n >> m;
vector<vector<ll>> e(n, vector<ll>(n, -1));
for (int i = 0, a, b, c; i < m; i++)
{
cin >> a >> b >> c;
--a, --b;
e[a][b] = c;
e[b][a] = c;
}
ll constexpr inf = 1e16;
vector<vector<ll>> d(1 << n, vector<ll>(n, -inf));
for (int i = 0; i < n; i++)
{
d[1 << i][i] = 0;
}
ll ans = 0;
for (int b = 0; b < (1 << n); b++)
{
for (int i = 0; i < n; i++)
{
chmax(ans, d[b][i]);
if(((b >> i) & 1) == 0) continue;
for (int j = 0; j < n; j++)
{
if(e[i][j] == -1) continue;
if((b >> j) & 1) continue;
chmax(d[b | (1 << j)][j], d[b][i] + e[i][j]);
}
}
}
cout << ans << endl;
}
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
solve();
}
Submission Info
| Submission Time | |
|---|---|
| Task | C - Remembering the Days |
| User | Motsu_xe |
| Language | C++ 20 (gcc 12.2) |
| Score | 300 |
| Code Size | 1288 Byte |
| Status | AC |
| Exec Time | 1 ms |
| Memory | 3712 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 300 / 300 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | sample_01.txt, sample_02.txt, sample_03.txt |
| All | random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, sample_01.txt, sample_02.txt, sample_03.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| random_01.txt | AC | 1 ms | 3664 KiB |
| random_02.txt | AC | 1 ms | 3592 KiB |
| random_03.txt | AC | 1 ms | 3584 KiB |
| random_04.txt | AC | 1 ms | 3600 KiB |
| random_05.txt | AC | 1 ms | 3596 KiB |
| random_06.txt | AC | 1 ms | 3400 KiB |
| random_07.txt | AC | 1 ms | 3568 KiB |
| random_08.txt | AC | 1 ms | 3536 KiB |
| random_09.txt | AC | 1 ms | 3636 KiB |
| random_10.txt | AC | 1 ms | 3536 KiB |
| random_11.txt | AC | 1 ms | 3640 KiB |
| random_12.txt | AC | 1 ms | 3512 KiB |
| random_13.txt | AC | 1 ms | 3588 KiB |
| random_14.txt | AC | 1 ms | 3532 KiB |
| random_15.txt | AC | 1 ms | 3636 KiB |
| random_16.txt | AC | 1 ms | 3544 KiB |
| random_17.txt | AC | 1 ms | 3508 KiB |
| random_18.txt | AC | 1 ms | 3660 KiB |
| random_19.txt | AC | 1 ms | 3652 KiB |
| random_20.txt | AC | 1 ms | 3656 KiB |
| random_21.txt | AC | 1 ms | 3656 KiB |
| sample_01.txt | AC | 1 ms | 3460 KiB |
| sample_02.txt | AC | 1 ms | 3648 KiB |
| sample_03.txt | AC | 1 ms | 3712 KiB |