Cod sursa(job #2436608)

Utilizator FunnyStockyMihnea Andreescu FunnyStocky Data 6 iulie 2019 14:05:19
Problema A+B Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.72 kb
#include <bits/stdc++.h>

using namespace std;

#define pb push_back
typedef long long ll;
const int N=(int)1e5+7;
int n,m,k;
ll dp[11][N];
vector<pair<int,int>>g[N];

int main()
{
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

        time_t a = clock_gettime(CLOCK_MONOTONIC, &programClockBegin);
        cout << a;
        return 0;

        cin>>n>>m>>k;
        for(int i=1;i<=m;i++)
        {
                int a,b,c;
                cin>>a>>b>>c;
                g[a].pb({b,c});
        }

        for(int i=1;i<11;i++)
                for(int j=0;j<N;j++)
                        dp[i][j]=(1LL<<60);

        for(int s=1;s<=k;s++)
        {
                dp[s][1]=0;
                queue<pair<ll,int>> q;
                /// dij algorithm
                q.push({0,1});
                while(!q.empty())
                {
                        pair<ll,int> it=q.front();
                        q.pop();
                        int nod=it.second;
                        ll c=-it.first;
                        if(c!=dp[s][nod])
                                continue;
                        for(auto &it2:g[nod])
                        {
                                int nou=it2.first;
                                ll posi=c+it2.second;
                                if(posi>dp[s-1][nou] && posi<dp[s][nou])
                                {
                                        dp[s][nou]=posi;
                                        q.push({-dp[s][nou],nou});
                                }
                        }
                }
                cout<<dp[s][n]<<" ";
             //   break;
        }
        cout<<"\n";

        return 0;
}