# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
199090 | dennisstar | Telegraph (JOI16_telegraph) | C++17 | 6 ms | 792 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define fi first
#define se second
#define em emplace
#define eb emplace_back
#define sq(X) ((X)*(X))
#define all(V) (V).begin(), (V).end()
#define chk_init memset(chk, 0, sizeof(chk))
#define unq(V) (V).erase(unique(all(V)), (V).end())
using namespace std;
typedef long long ll;
typedef vector<ll> vlm;
typedef vector<int> vim;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
int N, A[100010], chk[100010], cy[100010];
ll C[100010], S, ans, M1[100010], M2[100010];
int main() {
scanf("%d", &N);
for (int i=1; i<=N; i++) scanf("%d %lld", &A[i], &C[i]), S+=C[i];
int cnt=0;
for (int i=1; chk[i]==0; i=A[i]) chk[i]=1, cnt++;
if (cnt==N) { puts("0"); return 0; }
chk_init;
for (int i=1; i<=N; i++) if (chk[i]==0) {
int j; for (j=i; chk[j]==0; j=A[j]) chk[j]=i;
if (chk[j]==i) for (; cy[j]==0; j=A[j]) cy[j]=1;
}
for (int i=1; i<=N; i++) M1[A[i]]=max(M1[A[i]], C[i]);
for (int i=1; i<=N; i++) if (!cy[i]) M2[A[i]]=max(M2[A[i]], C[i]);
ll mx;
for (int i=1; i<=N; i++) {
ans+=M1[i];
if (cy[i]) {
mx=M2[i]-M1[i];
for (int j=i; cy[j]==1; j=A[j]) {
mx=max(mx, M2[j]-M1[j]);
cy[j]=0;
}
ans+=mx;
}
}
printf("%lld\n", S-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... |