#include <bits/stdc++.h>
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL)
#define file(a) freopen(a".inp","r",stdin); freopen(a".out", "w",stdout)
#define fi first
#define se second
#define endl "\n"
#define len(s) int32_t(s.length())
#define MASK(k)(1LL<<(k))
#define TASK "test"
#define int long long
using namespace std;
typedef tuple<int, int, int> tpiii;
typedef pair<double, double> pdd;
typedef pair<int, int> pii;
typedef long long ll;
const long long OO = 1e18;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const int MX = 300005;
int n, m;
int sum[MX];
int cnt[MX];
vector<pii> G[MX];
tpiii edges[MX<<1];
bitset<MX> ok = 0;
int cost[MX];
void nhap(){
cin >> n >> m;
for(int i=1; i<=m; i++){
int u, v, c;
cin >> u >> v >> c;
G[u].push_back({v, c});
G[v].push_back({u, c});
edges[i] = {c, u, v};
sum[u] += c;
sum[v] += c;
cnt[u]++;
cnt[v]++;
}
}
void solve(){
int ans = 0;
for(int i=1; i<=n; i++) ans = max(ans, sum[i]);
for(int i=1; i<=n; i++) if(cnt[i]*cnt[i]>=n){
for(pii &tmp: G[i]){
int j, c;
tie(j, c) = tmp;
ok[j] = 1;
cost[j] = c;
for(pii &tmp2: G[j]){
int k, f;
tie(k, f) = tmp2;
if(ok[k]) ans = max(ans, c + f + cost[k]);
}
}
for(pii &tmp: G[i]){
int f, k;
tie(f, k) = tmp;
ok[f] = cost[f] = 0;
}
}
sort(edges+1, edges+1+m, greater<tpiii>());
for(int i=1, f=0; i<=m; i++){
if(cnt[i]*cnt[i]>=n) continue;
else f++;
int c, u, v;
tie(c, u, v) = edges[i];
for(pii &tmp: G[u]){
int f, k;
tie(f, k) = tmp;
ok[f] = 1;
cost[f] = k;
}
for(pii &tmp: G[v]){
int f, k;
tie(f, k) = tmp;
if(ok[f]) ans = max(ans, c + k + cost[f]);
}
for(pii &tmp: G[u]){
int f, k;
tie(f, k) = tmp;
ok[f] = cost[f] = 0;
}
}
cout << ans;
}
int32_t main(){
fastIO;
file(TASK);
nhap();
solve();
return 0;
}
Compilation message
pigus_skrydziai.cpp: In function 'void solve()':
pigus_skrydziai.cpp:66:29: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
66 | ok[f] = cost[f] = 0;
| ~~~~~~~~^~~
pigus_skrydziai.cpp:89:29: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
89 | ok[f] = cost[f] = 0;
| ~~~~~~~~^~~
pigus_skrydziai.cpp: In function 'int32_t main()':
pigus_skrydziai.cpp:4:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
4 | #define file(a) freopen(a".inp","r",stdin); freopen(a".out", "w",stdout)
| ~~~~~~~^~~~~~~~~~~~~~~~~~~
pigus_skrydziai.cpp:97:5: note: in expansion of macro 'file'
97 | file(TASK);
| ^~~~
pigus_skrydziai.cpp:4:52: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
4 | #define file(a) freopen(a".inp","r",stdin); freopen(a".out", "w",stdout)
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
pigus_skrydziai.cpp:97:5: note: in expansion of macro 'file'
97 | file(TASK);
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
10584 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
10584 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
10584 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
10584 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |