# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
51771 | model_code | Telegraph (JOI16_telegraph) | C++17 | 51 ms | 58160 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <cstdio>
#include <algorithm>
using namespace std;
const int MAXN=100000;
int main()
{
int n;
scanf("%d",&n);
static int A[MAXN];
static long long C[MAXN];
for(int i=0;i<n;i++){
scanf("%d%lld",A+i,C+i);
A[i]--;
}
static int b[MAXN];
for(int i=0;i<n;i++){
b[i]=-1;
}
bool F=0;
for(int i=0;i<n;i++){
if(b[i]!=-1){
continue;
}
int j=i;
while(b[j]==-1){
b[j]=i;
j=A[j];
}
if(b[j]==i){
int C=0;
while(b[j]!=-2){
b[j]=-2;
j=A[j];
C++;
}
if(C==n){
F=1;
}
}
}
long long ans=0ll;
if(!F){
for(int i=0;i<n;i++){
ans+=C[i];
}
static long long M1[MAXN]={0},M2[MAXN]={0};
for(int i=0;i<n;i++){
M1[A[i]]=max(M1[A[i]],C[i]);
if(b[i]!=-2){
M2[A[i]]=max(M2[A[i]],C[i]);
}
}
for(int i=0;i<n;i++){
ans-=M1[i];
}
for(int i=0;i<n;i++){
if(b[i]!=-2){
continue;
}
long long M=10000000000ll;
int j=i;
while(b[j]==-2){
M=min(M,M1[j]-M2[j]);
b[j]=-3;
j=A[j];
}
ans+=M;
}
}
printf("%lld\n",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... |