| 23800 | 2026-01-29 21:08:08 | abcd | Villanyautó | cpp17 | Forditási hiba |
#include <bits/stdc++.h>
using namespace std;
using pii=pair<ll,ll>;
using ll=long long;
const ll maxn=101;
vector<pii> adj[maxn];
ll n,k;
pii best[maxn];
bool inq[maxn];
bool bfs(ll i,ll mx){
for(ll j=1;j<=n;j++) {
best[j]={-1,-1};
}
best[i]={1, mx};
queue<ll> q;
q.push(i);
inq[i]=true;
while(q.size()) {
ll 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(ll j=1;j<=n;j++) {
auto [b1,b2]=best[j];
if(b1>k||b1==-1)return false;
}
return true;
}
int main() {
ll m;cin>>n>>m>>k;
for(ll i=0;i<m;i++) {
ll 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(ll 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
*/open /var/local/lib/isolate/406/box/a.out: no such file or directory
main.cpp:3:16: error: 'll' was not declared in this scope
3 | using pii=pair<ll,ll>;
| ^~
main.cpp:3:19: error: 'll' was not declared in this scope
3 | using pii=pair<ll,ll>;
| ^~
main.cpp:3:21: error: template argument 1 is invalid
3 | using pii=pair<ll,ll>;
| ^
main.cpp:3:21: error: template argument 2 is invalid
main.cpp:7:8: error: 'pii' was not declared in this scope
7 | vector<pii> adj[maxn];
| ^~~
main.cpp:7:11: error: template argument 1 is invalid
7 | vector<pii> adj[maxn];
| ^
main.cpp:7:11: error: template argument 2 is invalid
main.cpp:9:1: error: 'pii' does not name a type
9 | pii best[maxn];
| ^~~
main.cpp: In function 'bool bfs(ll, ll)':
main.cpp:14:9: error: 'best' was not declared in this scope
14 | best[j]={-1,-1};
| ^~~~
main.cpp:16:5: error: 'best' was not declared in this scope
16 | best[i]={1, mx};
| ^~~~
main.cpp:23:32: error: 'begin' was not declared in this scope
23 | for(auto [u,cost]:adj[v]){
| ^
main.cpp:23:32: note: suggested alternatives:
In file included from /usr/include/x86_64-linux-gnu/c++/12/bits/stdc++.h:95,
from main.cpp:1:
/usr/include/c++/12/valarray:1226:5: note: 'std::begin'
1226 | begin(const valarray<_Tp>& __va) noexcept
| ^~~~~
In file included from /usr/include/c++/12/filesystem:46,
from /usr/include/x86_64-linux-gnu/c++/12/bits/stdc++.h:129:
/usr/include/c++/12/bits/fs_dir.h:557:3: note: 'std::filesystem::__cxx11::begin'
557 | begin(recursive_directory_iterator __iter) noexcept
| ^~~~~
main.cpp:23:32: error: 'end' was not declared in this scope
23 | for(auto [u,cost]:adj[v]){
| ^
main.cpp:23:32: note: suggested alternatives:
/usr/include/c++/12/valarray:1253:5: note: 'st...