提出 #55595549


ソースコード 拡げる

/*******************---------------SEE THE UNFORSEEN-----------------********************/

/* HEADERS <------------------------------------------------------------------------------*/
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// Template Credits :- https://github.com/zscoder/CompetitiveProgramming/blob/master/Data%20Structures%20Class%20Template.cpp


/* Debug Template <------------------------------------------------------------------------*/
#ifndef ONLINE_JUDGE
#include "dbg_template.cpp"
#else
#define debug(...)
#define debugArr(...)
#endif

/* NAMESPACES <----------------------------------------------------------------------------*/
using namespace std;
// using namespace __gnu_pbds;

/* DEFINE STATEMENTS <---------------------------------------------------------------------*/
#define  f(i,s,e) for(long long i=s;i<e;++i)
#define cf(i,s,e) for(long long i=s;i<=e;++i)
#define rf(i,e,s) for(long long i=e;i>=s;--i)
#define fe first
#define se second
#define pb push_back
#define eb emplace_back
#define fbo find_by_order  // gives itr to the x in indexed_set
#define ook order_of_key  // gives number of ele less then x in indexed_set
#define ist insert
#define mpr make_pair
#define endl '\n'
#define sz(x) ((long long int)(x).size())
#define all(a) begin(a), end(a)
#define fio ios_base:: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

/* OUTPUTS OF DS <-------------------------------------------------------------------------*/
#define outarr(arr) for(int i=0;i<(sizeof(arr)/sizeof(arr[0]));i++){ cout << arr[i] << " ";}cout << endl;
#define outvec(v) for(int i=0;i<sz(v);i++){ cout << v[i] << " ";}cout << endl;
#define outmap(m) for(auto i: m){ cout << i.fe << " " << i.se << endl;}
#define outvecvec(v) for(int i=0;i<sz(v);i++){for(int j=0;j<sz(v[i]);j++){cout << v[i][j] << " ";}cout << endl;}
#define outvecpair(v) for(int i=0;i<sz(v);i++){cout << v[i].first << " " << v[i].second << endl;}
#define outset(s) for(auto i : s){cout << i << " ";}cout<<endl;
#define outnum(n) cout << n << endl;

/* TYPEDEF STATEMENTS <---------------------------------------------------------------------*/
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef pair<ll,ll> pii;
typedef vector<pair<ll, ll>> vpii;
typedef vector<vector<ll>> vvi;
// template <typename T>
// using indexed_set = tree<T,null_type,less<T>,rb_tree_tag, tree_order_statistics_node_update>;

/* DEFINING CONSTANTS <----------------------------------------------------------------------*/
const static int M = 1e9+7;
const static ll INF = 2e18;
const static int mod = 998244353;


/* SOME HANDY FUNCTIONS <--------------------------------------------------------------------*/
void print_binary(ll num,ll n) { n--; while(n+1>0) { cout << (((num>>n)&1) > 0 ? 1 : 0); n--; } cout << endl;}
ll bin_exp(ll x, ll y) { ll res = 1; while(y>0) { if(y&1) { res = (res * x); } y>>=1; x = (x*x); } return res;}
// static vector<bool> isPrime(1ll*(1e7+10),1);
// static vi primes, lp(1ll*(1e7+10), 0), hp(1ll*(1e7+10), 0);
// void calc_sieve() {
//     isPrime[0]=isPrime[1]=false;

//     vi temp;
//     for(ll i=2; i<=1ll*(1e7+10); ++i) {
//         if(isPrime[i]==true) {
//             temp.pb(i);
//             lp[i] = hp[i] = i; //prime num hi low = num itself
//             for(ll j=2*i; j<=1ll*(1e7+10); j += i) {
//                 isPrime[j] = false;

//                 hp[j] = i; // highest prime which can divide n;
//                 if(lp[j] == 0) lp[j] = i; // lowest prime which can divide n;
//             }
//         }
//     }
//     primes = temp;
// }






/*
    Things to take care of :-
    1. If a[i] goes to 10^9, you only need to check for primes till sqrt(10^9) i.e 31623;
    2. Use sqrtl()
    3. For uniques in vector v ----> v.erase(unique(all(v)), v.end())
    4. Forward and Reverse Thinking....
    6. For checking parity ----> __builtin_parity(x);
    7. For counting set bits ----> __builtin_popcount(x);
    7. For counting leading zeros ----> __builtin_clz(x);
    7. For counting trailing zeros ----> __builtin_ctz(x);
    8. int log(long long x) return (64 - __builtin_clzll(x) - 1);
    9. use it for recursive lambda function --> function< ->return_type<- (ll, ll)> dfs = [&](ll u, ll parent)  {}
    10. Fenwick/Segment Tree with Coordinate Compression, Dynamic Seg tree.
*/

// bool isPrime(ll n) 
// { 
//     // Corner cases 
//     if (n <= 1)  return false; 
//     if (n <= 3)  return true; 
   
//     // This is checked so that we can skip  
//     // middle five numbers in below loop 
//     if (n%2 == 0 || n%3 == 0) return false; 
   
//     for (ll i=5; i*i<=n; i=i+6) 
//         if (n%i == 0 || n%(i+2) == 0) 
//            return false; 
   
//     return true; 
// } 

void solve() {
    ll n, m; cin >> n >> m;
    vi a(n); f(i,0,n) cin >> a[i];

    vector<vpii> g(n);
    f(i,0,m) {
        ll u, v, w; cin >> u >> v >> w;
        u--; v--;
        g[u].pb(mpr(v, w));
        g[v].pb(mpr(u, w));
    }

    vi dist(n, INF), vis(n);
    dist[0] = a[0];

    priority_queue<pii, vector<pii>, greater<pii>> q;
    q.push(mpr(a[0], 0));

    while(!q.empty()) {
        auto [d, u] = q.top(); q.pop();

        vis[u] = 1;

        for(auto [v, w] : g[u]) {
            if(vis[v]) continue;
            if(dist[v]  > w + a[v] + dist[u]) {
                dist[v] = w + a[v] + dist[u];
                q.push(mpr(dist[v], v));
            }
        }
    }
    debug(dist);
    f(i,1,n) cout << dist[i] << " ";
    cout << endl;
}

int main() {
    fio;

    // calc_sieve();
    int testcases=1; 
    // cin >> testcases;
    while(testcases--) solve();
    return 0;
}

提出情報

提出日時
問題 D - Shortest Path 3
ユーザ Spartan007
言語 C++ 20 (gcc 12.2)
得点 0
コード長 5872 Byte
結果 TLE
実行時間 2208 ms
メモリ 27956 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 0 / 425
結果
AC × 3
AC × 39
TLE × 2
セット名 テストケース
Sample 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt
All 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 01_random-small_01.txt, 01_random-small_02.txt, 01_random-small_03.txt, 01_random-small_04.txt, 01_random-small_05.txt, 01_random-small_06.txt, 01_random-small_07.txt, 01_random-small_08.txt, 01_random-small_09.txt, 01_random-small_10.txt, 01_random-small_11.txt, 01_random-small_12.txt, 01_random-small_13.txt, 01_random-small_14.txt, 01_random-small_15.txt, 02_random-large_01.txt, 02_random-large_02.txt, 02_random-large_03.txt, 02_random-large_04.txt, 02_random-large_05.txt, 02_random-large_06.txt, 02_random-large_07.txt, 02_random-large_08.txt, 02_random-large_09.txt, 02_random-large_10.txt, 02_random-large_11.txt, 02_random-large_12.txt, 02_random-large_13.txt, 02_random-large_14.txt, 02_random-large_15.txt, 03_handmade_01.txt, 03_handmade_02.txt, 03_handmade_03.txt, 03_handmade_04.txt, 03_handmade_05.txt, 03_handmade_06.txt, 03_handmade_07.txt, 03_handmade_08.txt
ケース名 結果 実行時間 メモリ
00_sample_01.txt AC 1 ms 3368 KiB
00_sample_02.txt AC 1 ms 3508 KiB
00_sample_03.txt AC 1 ms 3408 KiB
01_random-small_01.txt AC 1 ms 3544 KiB
01_random-small_02.txt AC 2 ms 3540 KiB
01_random-small_03.txt AC 1 ms 3616 KiB
01_random-small_04.txt AC 1 ms 3548 KiB
01_random-small_05.txt AC 35 ms 13212 KiB
01_random-small_06.txt AC 8 ms 5580 KiB
01_random-small_07.txt AC 5 ms 4460 KiB
01_random-small_08.txt AC 26 ms 10832 KiB
01_random-small_09.txt AC 1 ms 3484 KiB
01_random-small_10.txt AC 11 ms 6320 KiB
01_random-small_11.txt AC 3 ms 4220 KiB
01_random-small_12.txt AC 8 ms 5464 KiB
01_random-small_13.txt AC 34 ms 12076 KiB
01_random-small_14.txt AC 2 ms 3792 KiB
01_random-small_15.txt AC 10 ms 6080 KiB
02_random-large_01.txt AC 70 ms 14396 KiB
02_random-large_02.txt AC 134 ms 23364 KiB
02_random-large_03.txt AC 6 ms 4244 KiB
02_random-large_04.txt AC 151 ms 23400 KiB
02_random-large_05.txt AC 89 ms 16844 KiB
02_random-large_06.txt AC 159 ms 23336 KiB
02_random-large_07.txt AC 113 ms 18972 KiB
02_random-large_08.txt AC 147 ms 23492 KiB
02_random-large_09.txt AC 65 ms 13224 KiB
02_random-large_10.txt AC 155 ms 23368 KiB
02_random-large_11.txt AC 143 ms 22488 KiB
02_random-large_12.txt AC 146 ms 23300 KiB
02_random-large_13.txt AC 133 ms 20676 KiB
02_random-large_14.txt AC 159 ms 23432 KiB
02_random-large_15.txt AC 64 ms 14752 KiB
03_handmade_01.txt AC 133 ms 23300 KiB
03_handmade_02.txt AC 133 ms 23180 KiB
03_handmade_03.txt AC 119 ms 27956 KiB
03_handmade_04.txt AC 39 ms 13860 KiB
03_handmade_05.txt TLE 2208 ms 19148 KiB
03_handmade_06.txt TLE 2208 ms 18864 KiB
03_handmade_07.txt AC 1 ms 3580 KiB
03_handmade_08.txt AC 1 ms 3528 KiB