#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i = (begin); i < (end); i++)
#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr)
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define SZ(x) ((int)((x).size()))
#define LE(vec) vec[vec.size()-1]
#define TSTS int t; cin >> t; while(t--)solve()
const int INF = 1e9;
const long long LINF = 1e18;
const long double PI = asin(1)*2;
const int MOD = 1e9+7;
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef map<int, int> mii;
typedef long long ll;
typedef long double ld;
void setIO()
{
FAST_IO;
}
void setIO (string s)
{
setIO();
freopen((s+".in").c_str(),"r",stdin);
freopen((s+".out").c_str(),"w",stdout);
}
const int N=3e5+10, M=5e5+10;
int n, m;
ll cn[N], ans;
vi ad[N];
map<pii, ll> con;
int main()
{
setIO();
cin >> n >> m;
FOR(i, 0, m)
{
int a, b, c;
cin >> a >> b >> c;
cn[a-1]+=c;
cn[b-1]+=c;
ad[a-1].PB(b-1);
ad[b-1].PB(a-1);
con[{min(a-1, b-1), max(a-1, b-1)}]=c;
}
FOR(i, 0, n)
{
ans=max(ans, cn[i]);
}
FOR(i, 0, n)
{
vector<pii> full;
for(auto x : ad[i]){
for(auto y : ad[x]){
full.PB({y, x});
}
}
sort(full.begin(), full.end());
for(auto x : ad[i]){
int l=0, r=(int)full.size()-1;
while(l<r){
int m=(l+r+1)/2;
if(full[m].F<=x) l=m;
else r=m-1;
}
if(full[l].F==x){
//cout << i+1 << " " << x+1 << " " << full[l].S+1 << "\n";
ll val=con[{min(i, x), max(i, x)}]
+con[{min(x, full[l].S), max(x, full[l].S)}]
+con[{min(i, full[l].S), max(i, full[l].S)}];
ans=max(ans, val);
}
}
}
cout << ans;
}
Compilation message
pigus_skrydziai.cpp: In function 'void setIO(std::string)':
pigus_skrydziai.cpp:32:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
32 | freopen((s+".in").c_str(),"r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pigus_skrydziai.cpp:33:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
33 | freopen((s+".out").c_str(),"w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
7244 KB |
Output is correct |
2 |
Correct |
5 ms |
7244 KB |
Output is correct |
3 |
Correct |
5 ms |
7372 KB |
Output is correct |
4 |
Correct |
5 ms |
7364 KB |
Output is correct |
5 |
Correct |
5 ms |
7372 KB |
Output is correct |
6 |
Correct |
856 ms |
9928 KB |
Output is correct |
7 |
Correct |
6 ms |
7372 KB |
Output is correct |
8 |
Correct |
5 ms |
7372 KB |
Output is correct |
9 |
Correct |
5 ms |
7372 KB |
Output is correct |
10 |
Correct |
6 ms |
7372 KB |
Output is correct |
11 |
Correct |
8 ms |
7372 KB |
Output is correct |
12 |
Correct |
6 ms |
7372 KB |
Output is correct |
13 |
Correct |
6 ms |
7276 KB |
Output is correct |
14 |
Correct |
6 ms |
7244 KB |
Output is correct |
15 |
Correct |
5 ms |
7368 KB |
Output is correct |
16 |
Correct |
4 ms |
7244 KB |
Output is correct |
17 |
Correct |
5 ms |
7372 KB |
Output is correct |
18 |
Correct |
9 ms |
7372 KB |
Output is correct |
19 |
Correct |
14 ms |
7500 KB |
Output is correct |
20 |
Correct |
6 ms |
7392 KB |
Output is correct |
21 |
Correct |
6 ms |
7372 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
7244 KB |
Output is correct |
2 |
Correct |
5 ms |
7244 KB |
Output is correct |
3 |
Correct |
5 ms |
7372 KB |
Output is correct |
4 |
Correct |
5 ms |
7364 KB |
Output is correct |
5 |
Correct |
5 ms |
7372 KB |
Output is correct |
6 |
Correct |
856 ms |
9928 KB |
Output is correct |
7 |
Correct |
6 ms |
7372 KB |
Output is correct |
8 |
Correct |
5 ms |
7372 KB |
Output is correct |
9 |
Correct |
5 ms |
7372 KB |
Output is correct |
10 |
Correct |
6 ms |
7372 KB |
Output is correct |
11 |
Correct |
8 ms |
7372 KB |
Output is correct |
12 |
Correct |
6 ms |
7372 KB |
Output is correct |
13 |
Correct |
6 ms |
7276 KB |
Output is correct |
14 |
Correct |
6 ms |
7244 KB |
Output is correct |
15 |
Correct |
5 ms |
7368 KB |
Output is correct |
16 |
Correct |
4 ms |
7244 KB |
Output is correct |
17 |
Correct |
5 ms |
7372 KB |
Output is correct |
18 |
Correct |
9 ms |
7372 KB |
Output is correct |
19 |
Correct |
14 ms |
7500 KB |
Output is correct |
20 |
Correct |
6 ms |
7392 KB |
Output is correct |
21 |
Correct |
6 ms |
7372 KB |
Output is correct |
22 |
Execution timed out |
3039 ms |
53912 KB |
Time limit exceeded |
23 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
283 ms |
30712 KB |
Output is correct |
2 |
Correct |
671 ms |
42328 KB |
Output is correct |
3 |
Correct |
180 ms |
18872 KB |
Output is correct |
4 |
Correct |
370 ms |
30276 KB |
Output is correct |
5 |
Correct |
884 ms |
38928 KB |
Output is correct |
6 |
Execution timed out |
3050 ms |
21456 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
283 ms |
30712 KB |
Output is correct |
2 |
Correct |
671 ms |
42328 KB |
Output is correct |
3 |
Correct |
180 ms |
18872 KB |
Output is correct |
4 |
Correct |
370 ms |
30276 KB |
Output is correct |
5 |
Correct |
884 ms |
38928 KB |
Output is correct |
6 |
Execution timed out |
3050 ms |
21456 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |