74272024-01-08 20:46:55horvathabelVillanyautócpp17Wrong answer 9/60277ms4200 KiB
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
ll mx=100000000000;
vector<pair<ll,ll>> g[101];
bool dijkstra(ll mxut, ll k, ll x, ll n){
    priority_queue<pair<ll,ll>, vector<pair<ll,ll>>, greater<pair<ll,ll>>> q;
    vector<ll> maxk;
    maxk.resize(n+1,0);
    q.push({0,x});
    vector<ll>t;
    t.resize(101, mx);
    t[x]=0;
    while (!q.empty()){
        auto v=q.top();
        q.pop();

        for (auto edge:g[v.second]){
                bool van=false;
                if (t[edge.first]>edge.second+v.first){
                    if (edge.second+v.first>mxut){
                        if (edge.second<=mxut){;
                            t[edge.first]=edge.second;
                            maxk[edge.first]=max(maxk[edge.first], maxk[v.second]+1);
                            van=true;
                        }
                    }
                    else{
                            t[edge.first]=edge.second+v.first;
                            van=true;
                            }
                    if (van) q.push({t[edge.first],edge.first});
                }
        }
    }
    for (ll i=1; i<=n;i++) if (maxk[i]>k || t[i]==mx)  return false;
    return true;
}
int main()
{
    ll n,m,k;
    cin>>n>>m>>k;
    ll r=0;
    for (ll i=0; i<m;i++){
        ll a, b,c;
        cin>>a>>b>>c;
        r+=c;
        g[a].push_back({b,c});
        g[b].push_back({a,c});
    }
    ll l=0;
    while (l+1!=r){
         ll m=(l+r)/2;
         bool good=true;
         for (ll i=1; i<=n;i++){
                good=dijkstra(m, k, i, n);
         }
         if (good) r=m;
         else l=m;
    }
    cout<<l+1<<endl;
}
SubtaskSumTestVerdictTimeMemory
base9/60
1Accepted0/03ms1816 KiB
2Accepted0/0107ms2268 KiB
3Wrong answer0/118ms2256 KiB
4Wrong answer0/139ms2668 KiB
5Wrong answer0/148ms2632 KiB
6Wrong answer0/279ms3000 KiB
7Wrong answer0/2166ms3132 KiB
8Wrong answer0/2277ms3468 KiB
9Accepted1/14ms3100 KiB
10Wrong answer0/14ms3100 KiB
11Wrong answer0/14ms3236 KiB
12Wrong answer0/212ms3480 KiB
13Wrong answer0/29ms3356 KiB
14Wrong answer0/26ms3428 KiB
15Wrong answer0/39ms3536 KiB
16Wrong answer0/314ms3640 KiB
17Wrong answer0/214ms3524 KiB
18Wrong answer0/235ms3660 KiB
19Wrong answer0/235ms3900 KiB
20Wrong answer0/248ms3836 KiB
21Accepted2/228ms3812 KiB
22Wrong answer0/28ms3768 KiB
23Wrong answer0/348ms3888 KiB
24Wrong answer0/3133ms3956 KiB
25Wrong answer0/3136ms3852 KiB
26Wrong answer0/3210ms4168 KiB
27Accepted3/3115ms4200 KiB
28Wrong answer0/348ms3996 KiB
29Wrong answer0/345ms4144 KiB
30Accepted3/352ms4116 KiB