32892023-02-24 08:55:47rennTurista (40)cpp17Wrong answer 6/403ms3788 KiB
#include <bits/stdc++.h>
using namespace std;

int n, m, k, a, b, c, o = 0;
queue<int> path;

void dfs1(vector<vector<pair<int, int>>> &graf, vector<int> &arak, int j)
{
    for(auto &x : graf[j])
    {
        if(arak[j]+x.second < arak[x.first])
        {
            arak[x.first] = arak[j]+x.second;
            dfs1(graf, arak, x.first);
        }
    }
}

void dfs2(vector<vector<pair<int, int>>> &graf, vector<int> &arak, int j)
{
    for(auto &x : graf[j])
    {
        if(arak[j]+x.second == arak[x.first])
        {
            path.push(x.first);
            o += x.second*2;
            dfs2(graf, arak, x.first);
        }
    }
}


int main()
{

    cin.tie(0);
    ios::sync_with_stdio(0);

    cin >> n >> m >> k;

    vector<vector<pair<int, int>>> graf(n+1);
    vector<int> arak(n+1, 1000000);
    arak[k] = 0;
    
    while(m--)
    {
        cin >> a >> b >> c;
        graf[a].push_back({b, c});
        graf[b].push_back({a, c});
    }

    dfs1(graf, arak, k);
    dfs2(graf, arak, k);

    cout << o << "\n";
    while(!path.empty())
    {
        cout << path.front() << " ";
        path.pop();
    }
    cout << "\n";

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base6/40
1Accepted0/03ms1828 KiB
2Wrong answer0/03ms2060 KiB
3Accepted2/23ms2244 KiB
4Accepted2/23ms2452 KiB
5Accepted2/23ms2544 KiB
6Wrong answer0/23ms2664 KiB
7Wrong answer0/23ms2868 KiB
8Wrong answer0/22ms2948 KiB
9Wrong answer0/23ms3076 KiB
10Wrong answer0/23ms3308 KiB
11Wrong answer0/23ms3528 KiB
12Wrong answer0/23ms3596 KiB
13Wrong answer0/23ms3484 KiB
14Wrong answer0/23ms3488 KiB
15Wrong answer0/23ms3616 KiB
16Wrong answer0/23ms3712 KiB
17Wrong answer0/33ms3692 KiB
18Wrong answer0/33ms3788 KiB
19Wrong answer0/33ms3692 KiB
20Wrong answer0/33ms3700 KiB