74292024-01-08 20:57:13horvathabelVillanyautócpp17Wrong answer 9/60307ms3948 KiB
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
ll mx=100000000001;
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!=r){
         ll m=(l+r)/2;
         bool good=true;
         for (ll i=1; i<=n;i++){
                if (!dijkstra(m,k,i,n)) good=false;
         }
         if (good) r=m;
         else l=m+1;
    }
    cout<<l<<endl;
}
SubtaskSumTestVerdictTimeMemory
base9/60
1Accepted0/03ms1820 KiB
2Accepted0/0114ms2268 KiB
3Wrong answer0/120ms2432 KiB
4Wrong answer0/141ms2676 KiB
5Wrong answer0/152ms2920 KiB
6Wrong answer0/283ms2952 KiB
7Wrong answer0/2185ms3188 KiB
8Wrong answer0/2307ms3144 KiB
9Accepted1/14ms2988 KiB
10Wrong answer0/14ms3156 KiB
11Wrong answer0/14ms3296 KiB
12Wrong answer0/212ms3392 KiB
13Wrong answer0/28ms3384 KiB
14Wrong answer0/26ms3452 KiB
15Wrong answer0/39ms3548 KiB
16Wrong answer0/314ms3592 KiB
17Wrong answer0/213ms3520 KiB
18Wrong answer0/237ms3708 KiB
19Wrong answer0/237ms3580 KiB
20Wrong answer0/250ms3592 KiB
21Accepted2/228ms3672 KiB
22Wrong answer0/210ms3516 KiB
23Wrong answer0/350ms3528 KiB
24Wrong answer0/3142ms3604 KiB
25Wrong answer0/3145ms3752 KiB
26Wrong answer0/3230ms3792 KiB
27Accepted3/3122ms3828 KiB
28Wrong answer0/356ms3948 KiB
29Wrong answer0/350ms3656 KiB
30Accepted3/350ms3664 KiB