Submission #50169663


Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define fr first
#define sc second
#define endl '\n'
#define int long long
const ll mod = 1000000007, mod2 = 998244353;
const ll INF = 1e18 + 1;
vector<vector<pair<int, int>>> adj;
void solve(){
int n; cin >> n;
adj.resize(n);
for (ll i = 0; i < n - 1; ++i){
int x, y, z; cin >> x >> y >> z;
z--;
adj[i].pb({i + 1, x});
adj[i].pb({z, y});
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define fr first
#define sc second
#define endl '\n'
#define int long long

const ll mod = 1000000007, mod2 = 998244353;
const ll INF = 1e18 + 1;
vector<vector<pair<int, int>>> adj;

void solve(){
    int n; cin >> n;
    adj.resize(n);
    for (ll i = 0; i < n - 1; ++i){
        int x, y, z; cin >> x >> y >> z;
        z--;
        adj[i].pb({i + 1, x});
        adj[i].pb({z, y});
    }
    priority_queue<pair<int, int>> pq;
    vector<int> dis(n, INF);
    dis[0] = 0;
    pq.push({0, 0});
    vector<bool> pro(n, false);
    while(!pq.empty()){
        auto curr = pq.top();
        pq.pop();
        if(pro[curr.sc]) continue;
        pro[curr.sc] = true;
        for (auto [x, y] : adj[curr.sc]) {
            if(dis[x] > dis[curr.sc] + y){
                dis[x] = dis[curr.sc] + y;
                pq.push({-dis[x], x});
            }
        }
    }
    cout << dis[n - 1];
}

int32_t main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int tt = 1; 
    while(tt--){
        solve();
        cout << endl;
    }
    return 0;
}

Submission Info

Submission Time
Task D - Super Takahashi Bros.
User picramide
Language C++ 20 (gcc 12.2)
Score 425
Code Size 1191 Byte
Status AC
Exec Time 110 ms
Memory 19912 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 425 / 425
Status
AC × 3
AC × 19
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All min.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, sample_01.txt, sample_02.txt, sample_03.txt
Case Name Status Exec Time Memory
min.txt AC 1 ms 3400 KB
random_01.txt AC 104 ms 19912 KB
random_02.txt AC 47 ms 11560 KB
random_03.txt AC 110 ms 19844 KB
random_04.txt AC 104 ms 18860 KB
random_05.txt AC 45 ms 18688 KB
random_06.txt AC 32 ms 14116 KB
random_07.txt AC 47 ms 18668 KB
random_08.txt AC 4 ms 4232 KB
random_09.txt AC 49 ms 18756 KB
random_10.txt AC 33 ms 13324 KB
random_11.txt AC 51 ms 18620 KB
random_12.txt AC 9 ms 5760 KB
random_13.txt AC 41 ms 18692 KB
random_14.txt AC 41 ms 18656 KB
random_15.txt AC 1 ms 3368 KB
sample_01.txt AC 1 ms 3496 KB
sample_02.txt AC 1 ms 3508 KB
sample_03.txt AC 1 ms 3576 KB


2025-03-05 (Wed)
20:49:38 +00:00