# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
362489 | _martynas | Cheap flights (LMIO18_pigus_skrydziai) | C++11 | 1620 ms | 89304 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using ll = long long;
using pii = pair<int, int>;
const int MAX_N = 3e5+5;
const int MAX_M = 5e5+5;
#define PB push_back
#define F first
#define S second
int n, m;
vector<pii> Adj[MAX_N];
map<pii, int> M;
ll Star[MAX_N];
pii MaxWeight[MAX_N][2];
int main()
{
//freopen("lmio_2018_3e2_menesinis_bilietas_vyr.in", "r", stdin);
//freopen("lmio_2018_3e2_menesinis_bilietas_vyr.out", "w", stdout);
scanf("%d%d", &n, &m);
for(int i = 0; i < m; i++)
{
int a, b, w;
scanf("%d%d%d", &a, &b, &w);
a--;
b--;
Adj[a].PB({b, w});
Adj[b].PB({a, w});
Star[a] += w;
Star[b] += w;
M[{a, b}] = w;
M[{b, a}] = w;
}
ll ans = 0;
for(int i = 0; i < n; i++)
{
ans = max(ans, Star[i]);
MaxWeight[i][0] = MaxWeight[i][1] = {-1, 0};
for(pii e : Adj[i])
{
if(MaxWeight[i][0].S < e.S)
{
MaxWeight[i][0] = e;
if(MaxWeight[i][0].S > MaxWeight[i][1].S)
swap(MaxWeight[i][0], MaxWeight[i][1]);
}
}
if(MaxWeight[i][0].F != -1)
{
auto it = M.find({MaxWeight[i][0].F, MaxWeight[i][1].F});
if(it != M.end())
ans = max(ans, (ll)MaxWeight[i][0].S + MaxWeight[i][1].S + it->second);
}
}
printf("%lld", ans);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |