結果

問題 No.2805 Go to School
ユーザー Yoyoyo8128Yoyoyo8128
提出日時 2024-07-06 16:30:53
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 326 ms / 2,000 ms
コード長 9,698 bytes
コンパイル時間 4,059 ms
コンパイル使用メモリ 247,708 KB
実行使用メモリ 23,400 KB
最終ジャッジ日時 2024-07-16 01:36:38
合計ジャッジ時間 10,296 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 167 ms
16,768 KB
testcase_05 AC 208 ms
14,204 KB
testcase_06 AC 108 ms
9,368 KB
testcase_07 AC 102 ms
9,260 KB
testcase_08 AC 182 ms
14,288 KB
testcase_09 AC 107 ms
9,288 KB
testcase_10 AC 113 ms
9,188 KB
testcase_11 AC 326 ms
21,032 KB
testcase_12 AC 200 ms
14,656 KB
testcase_13 AC 290 ms
18,532 KB
testcase_14 AC 42 ms
6,944 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 1 ms
6,940 KB
testcase_17 AC 2 ms
6,944 KB
testcase_18 AC 148 ms
11,496 KB
testcase_19 AC 95 ms
8,816 KB
testcase_20 AC 231 ms
15,736 KB
testcase_21 AC 287 ms
20,184 KB
testcase_22 AC 123 ms
10,620 KB
testcase_23 AC 205 ms
14,564 KB
testcase_24 AC 202 ms
14,416 KB
testcase_25 AC 59 ms
8,888 KB
testcase_26 AC 241 ms
23,400 KB
testcase_27 AC 144 ms
16,700 KB
testcase_28 AC 12 ms
7,040 KB
testcase_29 AC 22 ms
7,936 KB
testcase_30 AC 78 ms
12,688 KB
testcase_31 AC 107 ms
10,368 KB
testcase_32 AC 221 ms
18,588 KB
testcase_33 AC 250 ms
18,964 KB
testcase_34 AC 2 ms
6,940 KB
testcase_35 AC 2 ms
6,944 KB
testcase_36 AC 99 ms
9,080 KB
testcase_37 AC 108 ms
10,240 KB
testcase_38 AC 199 ms
15,616 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'std::ostream& operator<<(std::ostream&, const std::map<T, S>&)':
main.cpp:198:16: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
  198 |     for (auto &[key, val] : m)
      |                ^

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
typedef vector<ll> vi;
typedef vector<vi> vvi;
const string Yes = "Yes";
const string No = "No";
const string YES = "YES";
const string NO = "NO";
const string abc = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const ll MOD = 1000000007;
const ll mod = 998244353;
const long long inf = 1LL << 60;
const long double PI = 3.141592653589793;
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define _GLIBCXX_DEBUG
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
const vector<int> dx = {0, 1, 0, -1};
const vector<int> dy = {1, 0, -1, 0};
using mint = modint998244353;
using Mint = modint1000000007;
#define YESNO(T)               \
    if (T)                     \
    {                          \
        cout << "YES" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "NO" << endl;  \
    }
#define yesno(T)               \
    if (T)                     \
    {                          \
        cout << "yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "no" << endl;  \
    }
#define YesNo(T)               \
    if (T)                     \
    {                          \
        cout << "Yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "No" << endl;  \
    }
#define inV(vec)                        \
    for (ll i = 0; i < vec.size(); i++) \
        cin >> vec[i];
#define outV(vec)                       \
    for (ll i = 0; i < vec.size(); i++) \
    {                                   \
        cout << vec[i] << " ";          \
    }                                   \
    cout << endl;
#define print(s) cout << s << endl;
#define updiv(n, x) (n + x - 1) / x
#define rounddiv(n, x) (ll)((double)(n) / (double)(x) + 0.5)
#define fix(n) fixed << setprecision(n);
#define ioinit                   \
    ios::sync_with_stdio(false); \
    std::cin.tie(nullptr)
template <typename T>
inline bool chmax(T &a, T b) { return ((a < b) ? (a = b, true) : (false)); }
template <typename T>
inline bool chmin(T &a, T b) { return ((a > b) ? (a = b, true) : (false)); }
template <class T>
ll sum(const T &a) { return accumulate(all(a), 0LL); }
#pragma region inout
// pair_out
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p)
{
    os << p.first << " " << p.second;
    return os;
}
// pair_in
template <typename T, typename U>
istream &operator>>(istream &is, pair<T, U> &p)
{
    is >> p.first >> p.second;
    return is;
}
// vector_out
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    int s = (int)v.size();
    for (int i = 0; i < s; i++)
        os << (i ? " " : "") << v[i];
    return os;
}
// vector_in
template <typename T>
istream &operator>>(istream &is, vector<T> &v)
{
    for (auto &x : v)
        is >> x;
    return is;
}
//__int128_t_in
istream &operator>>(istream &is, __int128_t &x)
{
    string S;
    is >> S;
    x = 0;
    int flag = 0;
    for (auto &c : S)
    {
        if (c == '-')
        {
            flag = true;
            continue;
        }
        x *= 10;
        x += c - '0';
    }
    if (flag)
        x = -x;
    return is;
}
//__uint128_t_in
istream &operator>>(istream &is, __uint128_t &x)
{
    string S;
    is >> S;
    x = 0;
    for (auto &c : S)
    {
        x *= 10;
        x += c - '0';
    }
    return is;
}
//__int128_t_out
ostream &operator<<(ostream &os, __int128_t x)
{
    if (x == 0)
        return os << 0;
    if (x < 0)
        os << '-', x = -x;
    string S;
    while (x)
        S.push_back('0' + x % 10), x /= 10;
    reverse(begin(S), end(S));
    return os << S;
}
//__uint128_t_out
ostream &operator<<(ostream &os, __uint128_t x)
{
    if (x == 0)
        return os << 0;
    string S;
    while (x)
        S.push_back('0' + x % 10), x /= 10;
    reverse(begin(S), end(S));
    return os << S;
}
// vector<vector>_out
template <typename T>
ostream &operator<<(ostream &os, const vector<vector<T>> &v)
{
    for (int i = 0; i < (int)v.size(); i++)
    {
        os << v[i] << endl;
    }
    return os;
}
// vector<vector<vector>>_out
template <typename T>
ostream &operator<<(ostream &os, const vector<vector<vector<T>>> &v)
{
    for (int i = 0; i < (int)v.size(); i++)
    {
        os << "i = " << i << endl;
        os << v[i];
    }
    return os;
}
// map_out
template <typename T, typename S>
ostream &operator<<(ostream &os, const map<T, S> &m)
{
    for (auto &[key, val] : m)
    {
        os << key << ":" << val << " ";
    }
    return os;
}
// set_out
template <typename T>
ostream &operator<<(ostream &os, const set<T> &st)
{
    auto itr = st.begin();
    for (int i = 0; i < (int)st.size(); i++)
    {
        os << *itr << (i + 1 != (int)st.size() ? " " : "");
        itr++;
    }
    return os;
}
// multiset_out
template <typename T>
ostream &operator<<(ostream &os, const multiset<T> &st)
{
    auto itr = st.begin();
    for (int i = 0; i < (int)st.size(); i++)
    {
        os << *itr << (i + 1 != (int)st.size() ? " " : "");
        itr++;
    }
    return os;
}
// queue_out
template <typename T>
ostream &operator<<(ostream &os, queue<T> q)
{
    while (q.size())
    {
        os << q.front() << " ";
        q.pop();
    }
    return os;
}
// deque_out
template <typename T>
ostream &operator<<(ostream &os, deque<T> q)
{
    while (q.size())
    {
        os << q.front() << " ";
        q.pop_front();
    }
    return os;
}
// stack_out
template <typename T>
ostream &operator<<(ostream &os, stack<T> st)
{
    while (st.size())
    {
        os << st.top() << " ";
        st.pop();
    }
    return os;
}
// priority_queue_out
template <class T, class Container, class Compare>
ostream &operator<<(ostream &os, priority_queue<T, Container, Compare> pq)
{
    while (pq.size())
    {
        os << pq.top() << " ";
        pq.pop();
    }
    return os;
}
#if __has_include(<atcoder/all>)
// 998244353_in
istream &operator>>(istream &a, mint &b)
{
    long long tmp;
    a >> tmp;
    b = tmp;
    return a;
}
// 998244353_out
ostream &operator<<(ostream &a, mint &b)
{
    a << b.val();
    return a;
}
// 1000000007_in
istream &operator>>(istream &a, Mint &b)
{
    long long tmp;
    a >> tmp;
    b = tmp;
    return a;
}
// 1000000007_out
ostream &operator<<(ostream &a, Mint &b)
{
    a << b.val();
    return a;
}
#endif

#pragma endregion inout

// 繰り返し二乗法
ll modpow(ll a, ll n, ll mod)
{
    if (a == 0)
    {
        return 0;
    }
    ll res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

// 割り算
ll Div(ll a, ll b, ll m)
{
    return (a * modpow(b, m - 2, m)) % m;
}

// 階乗
vector<ll> fact(1);
void fac(ll N, ll m)
{
    fact[0] = 1;
    for (int i = 1; i <= N; i++)
    {
        ll ppp = i;
        while (ppp % m == 0)
        {
            ppp /= m;
        }
        fact.pb(fact[i - 1] * (ppp));
        fact[i] %= m;
    }
}

ll v(ll n, ll p)
{
    ll aaans = 0;
    ll nppp = n;
    while (nppp > 0)
    {
        aaans += nppp / p;
        nppp /= p;
    }
    return aaans;
}
// 組み合わせ
ll comb(ll n, ll r, ll m)
{
    if (n < r)
    {
        return 0;
    }

    if (r < 0)
    {
        return 0;
    }

    if (n < 0)
    {
        return 0;
    }
    return Div(fact[n], fact[r] * fact[n - r] % m, m);
}

ll mex(ll a, ll b)
{
    if (a > b)
    {
        swap(a, b);
    }
    if (a != 0)
    {
        return 0;
    }
    else
    {
        if (b != 1)
        {
            return 1;
        }
        else
        {
            return 2;
        }
    }
}

// ダイクストラ
struct Edge
{
    long long to;
    long long cost;
};
void dijkstra(const vector<vector<Edge>> &G, int s, vector<long long> &dis)
{
    int N = G.size();
    dis.resize(N, inf);
    priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<pair<long long, int>>> pq; // 「仮の最短距離, 頂点」が小さい順に並ぶ
    dis[s] = 0;
    pq.emplace(dis[s], s);
    while (!pq.empty())
    {
        pair<long long, int> p = pq.top();
        pq.pop();
        int v = p.second;
        if (dis[v] < p.first)
        { // 最短距離で無ければ無視
            continue;
        }
        for (auto &e : G[v])
        {
            if (dis[e.to] > dis[v] + e.cost)
            { // 最短距離候補なら priority_queue に追加
                dis[e.to] = dis[v] + e.cost;
                pq.emplace(dis[e.to], e.to);
            }
        }
    }
}
// https://algo-logic.info/dijkstra/


int main()
{
    ll N,M,L,S,E;
    cin>>N>>M>>L>>S>>E;
    vector<vector<Edge>>Gra(N,vector<Edge>());
    for(int i=0;i<M;i++){
        ll a,b,t;
        cin>>a>>b>>t;
        a--;b--;
        //print("sa");
        Gra[a].pb({b,t});
        //print(i);
        Gra[b].pb({a,t});
    }
    
    vector<ll>dis1(N,inf);
    vector<ll>dis2(N,inf);
    dijkstra(Gra,0,dis1);
    dijkstra(Gra,N-1,dis2);
    vector<ll>T(L);
    cin>>T;
    ll ans=1145141919810ll;
    
    for(int i=0;i<L;i++){
        T[i]--;
        if(dis1[T[i]]<=S+E){
            chmin(ans,max(dis1[T[i]],S)+1+dis2[T[i]]);
        }
    }
    if(ans==1145141919810ll){
        print(-1);
        exit(0);
    }
    print(ans);
}
0