#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i = (begin); i < (end); i++)
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define F first
#define S second
#define PB push_back
#define MP make_pair
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef long long ll;
void setIO()
{
FAST_IO;
}
const int N=3e5+100, M=5e5+100;
int n, m; ll cnt[N];
vector<pii> ad[N];
set<pii> ins;
bool v[N];
void dfs(int u, int pst)
{
v[u]=true;
for(auto it : ad[u])
{
int b=it.F, w=it.S;
cnt[u]+=w;
cnt[b]+=w;
if(!v[b])
dfs(b, u);
else if(b!=pst)
{
ins.insert(MP(min(u, b), max(u, b)));
}
}
}
map<int, bool> con[N];
map<pii, int> pth;
map<pair<int, pii>, bool> done;
int main()
{
setIO();
cin >> n >> m;
FOR(i, 0, m)
{
int a, b, c;
cin >> a >> b >> c;
con[a][b]=true;
con[b][a]=true;
ad[a-1].PB(MP(b-1, c));
ad[b-1].PB(MP(a-1, c));
pth[MP(min(a-1, b-1), max(a-1, b-1))]=c;
}
dfs(0, -1);
ll mx=-1;
FOR(i, 0, n) mx=max(mx, cnt[i]/2);
for(auto[x, y] : ins)
{
FOR(i, 0, n)
{
if(i==x||i==y) continue;
if(con[x][i] && con[y][i])
{
ll tot=pth[MP(min(x, y), max(x, y))]+
pth[MP(min(x, i), max(x, i))]+
pth[MP(min(y, i), max(y, i))];
vi ths; ths.PB(x); ths.PB(y); ths.PB(i);
sort(ths.begin(), ths.end());
if(!done[MP(ths[0],MP(ths[1], ths[2]))])
{
done[MP(ths[0],MP(ths[1], ths[2]))]=true;
mx=max(mx, tot);
}
}
}
}
cout << mx;
}
Compilation message
pigus_skrydziai.cpp: In function 'int main()':
pigus_skrydziai.cpp:67:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
67 | for(auto[x, y] : ins)
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
21452 KB |
Output is correct |
2 |
Correct |
13 ms |
21352 KB |
Output is correct |
3 |
Correct |
14 ms |
21452 KB |
Output is correct |
4 |
Correct |
15 ms |
21408 KB |
Output is correct |
5 |
Correct |
13 ms |
21476 KB |
Output is correct |
6 |
Execution timed out |
3103 ms |
102960 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
21452 KB |
Output is correct |
2 |
Correct |
13 ms |
21352 KB |
Output is correct |
3 |
Correct |
14 ms |
21452 KB |
Output is correct |
4 |
Correct |
15 ms |
21408 KB |
Output is correct |
5 |
Correct |
13 ms |
21476 KB |
Output is correct |
6 |
Execution timed out |
3103 ms |
102960 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
373 ms |
54268 KB |
Output is correct |
2 |
Correct |
922 ms |
91892 KB |
Output is correct |
3 |
Incorrect |
254 ms |
44920 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
373 ms |
54268 KB |
Output is correct |
2 |
Correct |
922 ms |
91892 KB |
Output is correct |
3 |
Incorrect |
254 ms |
44920 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |