237992026-01-29 20:52:23abcdVillanyautócpp17Wrong answer 52/6094ms496 KiB
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;

const int maxn=101;
vector<pii> adj[maxn];
int n,k;
pii best[maxn];
bool inq[maxn];

bool bfs(int i,int mx){
    for(int j=1;j<=n;j++) {
        best[j]={-1,-1};
    }
    best[i]={1, mx};
    queue<int> q;
    q.push(i);
    inq[i]=true;
    while(q.size()) {
        int v=q.front();q.pop();
        inq[v]=false;
        for(auto [u,cost]:adj[v]){
            if(cost>mx)continue;
            auto [vb1,vb2]=best[v];
            if(vb2<cost){
                vb1++;
                vb2=mx-cost;
            }else vb2-=cost;
            auto [ub1,ub2]=best[u];
            if(ub1==-1)best[u]={vb1,vb2};
            else if(ub1>vb1)best[u]={vb1,vb2};
            else if(ub1==vb1&&ub2<vb2)best[u]={vb1,vb2};
            if(make_pair(ub1,ub2)!=best[u]&&inq[u]==false){
                q.push(u);
                inq[u]=true;
            }
        }
    }
    for(int j=1;j<=n;j++) {
        auto [b1,b2]=best[j];
        if(b1>k||b1==-1)return false;
    }
    return true;
}

int main() {
    int m;cin>>n>>m>>k;
    for(int i=0;i<m;i++) {
        int a,b,c;cin>>a>>b>>c;
        adj[a].push_back({b,c});
        adj[b].push_back({a,c});
    }
    ll l=1,r=1e9;
    while (l<r){
        ll mid=(l+r)/2;
        bool ok=true;
        for(int i=1;i<=n;i++)
            if(!bfs(i,mid)){
                ok=false;break;
            }
        if(ok){
            r=mid;
        }else l=mid+1;
    }
    cout<<r<<'\n';
}

/*
4 4 2   
1 2 1
2 3 2
3 4 3
4 1 4
*/
SubtaskSumTestVerdictTimeMemory
base52/60
1Accepted0/01ms316 KiB
2Accepted0/094ms316 KiB
3Wrong answer0/11ms316 KiB
4Accepted1/110ms316 KiB
5Accepted1/113ms444 KiB
6Wrong answer0/21ms408 KiB
7Accepted2/254ms452 KiB
8Accepted2/290ms496 KiB
9Accepted1/14ms316 KiB
10Accepted1/13ms316 KiB
11Accepted1/13ms316 KiB
12Accepted2/217ms316 KiB
13Accepted2/29ms404 KiB
14Accepted2/27ms404 KiB
15Accepted3/312ms404 KiB
16Accepted3/332ms444 KiB
17Wrong answer0/21ms316 KiB
18Accepted2/213ms420 KiB
19Accepted2/212ms436 KiB
20Accepted2/217ms444 KiB
21Accepted2/214ms420 KiB
22Accepted2/24ms316 KiB
23Wrong answer0/31ms316 KiB
24Accepted3/357ms416 KiB
25Accepted3/352ms448 KiB
26Accepted3/390ms468 KiB
27Accepted3/370ms432 KiB
28Accepted3/320ms412 KiB
29Accepted3/310ms408 KiB
30Accepted3/318ms412 KiB