Submission #57301457
Source Code Expand
#ifdef LOCAL
//#define _GLIBCXX_DEBUG
#else
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx512f,avx512dq,avx512cd,avx512bw,avx512vl")
#endif
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<char> Vc;
typedef vector<P> VP;
typedef vector<VP> VVP;
typedef vector<Vec> VV;
typedef vector<Vi> VVi;
typedef vector<Vc> VVc;
typedef vector<VV> VVV;
typedef vector<VVV> VVVV;
typedef vector<VVVV> VVVVV;
typedef vector<VVVV> VVVVVV;
#define MAKEVV(variable, a, ...) VV variable(a, Vec(__VA_ARGS__))
#define MAKEVVc(variable, a, ...) VVc variable(a,Vc(__VA_ARGS__))
#define MAKEVVV(variable, a, b, ...) VVV variable(a, VV(b, Vec(__VA_ARGS__)))
#define MAKEVVVV(variable, a, b, c, ...) VVVV variable(a, VVV(b, (VV(c, Vec(__VA_ARGS__)))))
#define MAKEVVVVV(variable, a, b, c, d, ...) VVVVV variable(a, VVVV(b, (VVV(c, VV(d, Vec(__VA_ARGS__))))))
#define MAKEVVVVVV(variable, a, b, c, d, e, ...) VVVVVV variable(a, VVVVV(b, (VVVV(c, VVV(d, VV(e, Vec(__VA_ARGS__)))))))
#define endl '\n'
#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF = 4'000'000'000'000'000'010LL;
const ll MOD=998244353;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define rEach(i, mp) for (auto i = mp.rbegin(); i != mp.rend(); ++i)
#define SUM(a) accumulate(ALL(a),0LL)
#define outminusone(a) cout<< ( a==INF ? -1 : a ) <<endl
#define Uniq(v) v.erase(unique(v.begin(), v.end()), v.end())
#define fi first
#define se second
template<class T, class S>bool chmax(T &a, const S &b) { if (a<b) { a=b; return true; } return false; }
template<class T, class S>bool chmin(T &a, const S &b) { if (b<a) { a=b; return true; } return false; }
template<class T>auto lb(vector<T> &X, T x){return lower_bound(ALL(X),x) - X.begin();}
template<class T>auto ub(vector<T> &X, T x){return upper_bound(ALL(X),x) - X.begin();}
ll popcnt(ll x){return __builtin_popcount(x);}
ll topbit(ll t){return t==0?-1:63-__builtin_clzll(t);}
ll floor(ll y,ll x){assert(x != 0);if(x < 0){y *= -1; x *= -1;}if(y < 0){return (y-x+1)/x;}return y/x;};
ll ceil(ll y, ll x){assert(x != 0);if(x < 0){y *= -1; x *= -1;}if(y < 0){return y/x;}return (y+x-1)/x;};
auto hasbit = [](ll x, ll i )->bool{return (1LL<<i) & x;};//xにi番目のbitが立っているか
template<typename T1, typename T2>istream &operator>>(istream &i, pair<T1, T2> &p) { return i>>p.first>>p.second; }
template<typename T>istream& operator>>(istream&i,vector<T>&v){rep(j,v.size())i>>v[j];return i;}
template<typename T1, typename T2>ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }
template<class T>ostream &operator<<(ostream &os, const vector<T> &v) {bool f = false;for(const auto &d: v) {if(f) os<<" ";f = true;
// #ifdef LOCAL
// if(d == INF){os<<"X";}else if(d == -INF){os<<"-X";}else{os<<d;}
// #else
// os<<d;
// #endif
os<<d;
}return os;}
template <class T> ostream& operator<<(ostream& os, const set<T>& s) {os << "{";bool f = false;for (auto d : s) {if (f) os << ", ";f = true;os << d;}return os << "}";}
template <class T> ostream& operator<<(ostream& os, const multiset<T>& s) {os << "{";bool f = false;for (auto d : s) {if (f) os << ", ";f = true;os << d;}return os << "}";}
template<class T, class U>ostream &operator<<(ostream &os, const map<T, U> &s) {bool f = false;os<<endl;for(auto p: s) {if(f) os<<endl;f = true;os<<p.first<<": "<<p.second;}return os<<endl;}
void out() { cout << endl; }
template <class Head, class... Tail> void out(const Head &head, const Tail &...tail) {cout << head;if(sizeof...(tail)) cout << ' ';out(tail...);}
#ifdef LOCAL
template<typename T>ostream &operator<<(ostream &s, const vector<vector<T>> &vv) {int len=vv.size();for(int i=0; i<len; ++i) {if(i==0)s<<endl;s<<i<<":"<<vv[i];if(i!=len-1)s<<endl;}return s;}
struct PrettyOS {ostream& os;bool first;template <class T> auto operator<<(T&& x) {if (!first) os << ", ";first = false;os << x;return *this;}};
template <class... T> void dbg0(T&&... t) {(PrettyOS{cerr, true} << ... << t);}
#define dbg(...)do {cerr << #__VA_ARGS__ << ": ";dbg0(__VA_ARGS__);cerr << endl;} while (false);
#else
#define dbg(...)
#endif
int solve(){
ll n;
cin>>n;
ll m;
cin>>m;
VVP g(n);
/*
* 3000 * 120 * 32
* n = 400 少ないww
* Q = 3000
* K = 5
* 橋を渡る u --m_i-- v
* 順番だけ気にすれば良さそう
* 1 -> n
*/
VV d(n, Vec(n,INF));
VP vp(m);
Vec T(m);
rep(i,n)d[i][i]=0;
rep(i,m) {
ll u,v,t;
cin>>u>>v>>t;
u--;v--;
chmin(d[u][v],t);
chmin(d[v][u],t);
vp[i] = mp(u,v);
T[i] = t;
}
rep(k,n){
rep(i,n){
rep(j,n) {
chmin(d[i][j], d[i][k]+d[k][j]);
}
}
}
ll Q;
cin>>Q;
while(Q--) {
ll ans = INF;
ll k;
cin>>k;
Vec b(k);
cin>>b;
rep(i,k)b[i]--;
dbg(b);
ll bits = 1LL<<k;
Vec I(k);
iota(ALL(I),0);
do {
rep(bit, bits) {
ll sum = 0;
VP vp2;
rep(i,k) {
ll u = vp[b[I[i]]].fi;
ll v = vp[b[I[i]]].se;
if(hasbit(bit,i)) {
swap(u,v);
}
vp2.emplace_back(u,v);
sum += T[b[I[i]]];
}
rep(i,k-1) {
sum += d[vp2[i].se][vp2[i+1].fi];
}
sum += d[0][vp2[0].fi];
sum += d[vp2[k-1].se][n-1];
chmin(ans, sum);
}
}while(next_permutation(ALL(I)));
out(ans);
}
return 0;
}
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout<<std::setprecision(20);
// ll T;
// cin>>T;
// while(T--)
solve();
}
Submission Info
Submission Time
2024-08-31 21:32:16+0900
Task
E - Sightseeing Tour
User
hamath
Language
C++ 20 (gcc 12.2)
Score
450
Code Size
6654 Byte
Status
AC
Exec Time
919 ms
Memory
9096 KiB
Compile Error
Main.cpp: In instantiation of ‘std::istream& operator>>(std::istream&, std::vector<_Tp>&) [with T = long long int; std::istream = std::basic_istream<char>]’:
Main.cpp:136:14: required from here
Main.cpp:38:37: warning: comparison of integer expressions of different signedness: ‘ll’ {aka ‘long long int’} and ‘std::vector<long long int>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
38 | #define REP(i, a, b) for(ll i=(a); i<(b); i++)
| ^
Main.cpp:40:19: note: in expansion of macro ‘REP’
40 | #define rep(i, n) REP(i, 0, n)
| ^~~
Main.cpp:69:64: note: in expansion of macro ‘rep’
69 | template<typename T>istream& operator>>(istream&i,vector<T>&v){rep(j,v.size())i>>v[j];return i;}
| ^~~
Judge Result
Set Name
Sample
All
Score / Max Score
0 / 0
450 / 450
Status
Set Name
Test Cases
Sample
example_00.txt, example_01.txt, example_02.txt
All
example_00.txt, example_01.txt, example_02.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, random_00.txt, 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, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt
Case Name
Status
Exec Time
Memory
example_00.txt
AC
1 ms
3488 KiB
example_01.txt
AC
1 ms
3632 KiB
example_02.txt
AC
1 ms
3448 KiB
hand_00.txt
AC
851 ms
4720 KiB
hand_01.txt
AC
859 ms
4780 KiB
hand_02.txt
AC
212 ms
7872 KiB
hand_03.txt
AC
893 ms
6236 KiB
hand_04.txt
AC
906 ms
9096 KiB
hand_05.txt
AC
864 ms
4556 KiB
random_00.txt
AC
213 ms
4444 KiB
random_01.txt
AC
856 ms
4388 KiB
random_02.txt
AC
846 ms
4540 KiB
random_03.txt
AC
216 ms
4332 KiB
random_04.txt
AC
856 ms
4500 KiB
random_05.txt
AC
854 ms
4424 KiB
random_06.txt
AC
228 ms
4608 KiB
random_07.txt
AC
865 ms
4484 KiB
random_08.txt
AC
872 ms
4660 KiB
random_09.txt
AC
221 ms
4520 KiB
random_10.txt
AC
867 ms
4760 KiB
random_11.txt
AC
869 ms
4580 KiB
random_12.txt
AC
235 ms
4600 KiB
random_13.txt
AC
869 ms
4620 KiB
random_14.txt
AC
882 ms
4544 KiB
random_15.txt
AC
234 ms
4552 KiB
random_16.txt
AC
887 ms
4856 KiB
random_17.txt
AC
871 ms
4676 KiB
random_18.txt
AC
237 ms
4864 KiB
random_19.txt
AC
872 ms
4756 KiB
random_20.txt
AC
894 ms
4756 KiB
random_21.txt
AC
244 ms
5164 KiB
random_22.txt
AC
887 ms
5168 KiB
random_23.txt
AC
895 ms
5216 KiB
random_24.txt
AC
245 ms
5928 KiB
random_25.txt
AC
879 ms
5368 KiB
random_26.txt
AC
882 ms
6008 KiB
random_27.txt
AC
245 ms
6584 KiB
random_28.txt
AC
919 ms
8080 KiB
random_29.txt
AC
891 ms
6760 KiB