Submission #3269501
Source Code Expand
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
int N, M, R;
vector<int> order;
vector<vector<P>> root(201); //pair<辺の距離, 行先の頂点>
vector<vector<ll>> dist(8, vector<ll>(201, LLONG_MAX)); //distance[i]は始点(start)から頂点iへの最短距離が入る
bitset<201> used;
void Dijkstra(int r, int start){ //start = 始点
priority_queue<P, vector<P>, greater<P>> que;
que.push(make_pair(0, start));
used.reset();
while(!que.empty()){
ll d, t; //d:startからの距離, t:行先
tie(d, t) = que.top(); que.pop();
if(used[t]) continue; //探索済み
used[t] = true, dist[r][t] = d;
for(auto e : root[t]){
if(dist[r][e.second] <= d + e.first) continue;
que.push(make_pair(d + e.first, e.second));
}
}
}
ll ans = LLONG_MAX;
bitset<8> bit;
void rec(int corrent, int count, ll sum){
if(count == R){
ans = min(ans, sum);
return;
}
if(sum >= ans) return;
for(int i = 0; i < R; ++i){
int a = corrent, b = order[i];
if(!bit[i] && dist[a][b] != LLONG_MAX){
bit[i] = true;
rec(i, count + 1, sum + dist[a][b]);
bit[i] = false;
}
}
return;
}
int main(void){
scanf("%d %d %d", &N, &M, &R);
for(int i = 0; i < R; ++i){
int a; scanf("%d", &a);
order.push_back(a);
}
for(int i = 0; i < M; ++i){
ll a, b, c; scanf("%lld %lld %lld", &a, &b, &c);
root[a].push_back(make_pair(c, b)), root[b].push_back(make_pair(c, a));
}
for(int i = 0; i < R; ++i) Dijkstra(i, order[i]);
for(int i = 0; i < R; ++i){
bit.reset();
bit[i] = true;
rec(i, 1, 0);
bit[i] = false;
}
printf("%lld\n", ans);
return 0;
}
Submission Info
Submission Time |
|
Task |
D - joisino's travel |
User |
sgneet |
Language |
C++14 (GCC 5.4.1) |
Score |
400 |
Code Size |
1993 Byte |
Status |
AC |
Exec Time |
29 ms |
Memory |
2004 KB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:51:34: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d", &N, &M, &R);
^
./Main.cpp:53:31: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
int a; scanf("%d", &a);
^
./Main.cpp:58:56: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
ll a, b, c; scanf("%lld %lld %lld", &a, &b, &c);
^
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
400 / 400 |
Status |
|
|
Set Name |
Test Cases |
Sample |
sample_01.txt, sample_02.txt, sample_03.txt |
All |
01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, sample_01.txt, sample_02.txt, sample_03.txt |
Case Name |
Status |
Exec Time |
Memory |
01.txt |
AC |
28 ms |
2004 KB |
02.txt |
AC |
2 ms |
256 KB |
03.txt |
AC |
2 ms |
256 KB |
04.txt |
AC |
4 ms |
384 KB |
05.txt |
AC |
8 ms |
732 KB |
06.txt |
AC |
29 ms |
2004 KB |
07.txt |
AC |
28 ms |
2004 KB |
08.txt |
AC |
3 ms |
256 KB |
sample_01.txt |
AC |
1 ms |
256 KB |
sample_02.txt |
AC |
1 ms |
256 KB |
sample_03.txt |
AC |
1 ms |
256 KB |