이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
int n,m;
typedef long long ll;
struct el {
int a,b;
ll c;
bool operator<(const el& masik) const {
if(a==masik.a) return b<masik.b;
return a<masik.a;
}
};
vector<el> lst;
vector<pair<int, ll>> adj[300001];
ll cost(int a, int b) {
if(a>b) swap(a,b);
auto it=lower_bound(lst.begin(),lst.end(), el{a,b,0});
if(it==lst.end() || it->a!=a || it->b!=b) return 0;
return it->c;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n>>m;
for(int i=0;i<m;++i) {
int a,b,c;
cin>>a>>b>>c;
lst.push_back({min(a,b),max(a,b),c});
adj[a].push_back({b,c});
adj[b].push_back({a,c});
}
sort(lst.begin(),lst.end());
ll ans=0;
for(int i=1;i<=n;++i) {
ll cans=0;
for(auto j:adj[i]) {
cans+=j.second;
}
ans=max(ans, cans);
}
const int lim=200;
for(int i=1;i<=n;++i) {
if(adj[i].size()<=lim) {
for(int j=0;j<adj[i].size();++j) {
for(int k=j+1;k<adj[i].size();++k) {
ans=max(ans, adj[i][j].second+adj[i][k].second+cost(adj[i][j].first, adj[i][k].first));
}
}
}else {
vector<int> kell(n+1);
for(auto j:adj[i]) {
kell[j.first]=j.second;
}
for(auto j:adj[i]) {
for(auto k:adj[j.first]) {
if(kell[k.first]) ans=max(ans, k.second+j.second+kell[k.first]);
}
}
}
}
cout<<ans<<"\n";
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
pigus_skrydziai.cpp: In function 'int main()':
pigus_skrydziai.cpp:46:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=0;j<adj[i].size();++j) {
~^~~~~~~~~~~~~~
pigus_skrydziai.cpp:47:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int k=j+1;k<adj[i].size();++k) {
~^~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |