Submission #134653

# Submission time Handle Problem Language Result Execution time Memory
134653 2019-07-23T06:35:24 Z 이온조(#3239) Telegraph (JOI16_telegraph) C++14
0 / 100
2 ms 376 KB
#include <bits/stdc++.h>
using namespace std;

const long long INF = 1LL * 1e18;
long long P[100009], D[100009];
int N, A[100009], C[100009];

void go(int x, int msk) {
	if(msk == (1 << N) - 1) {
		puts("0");
		exit(0);
	}
	P[msk] = C[x];
	if(msk & (1 << (A[x]-1))) return;
	go(A[x], msk | (1 << (A[x]-1)));
}

int main() {
	scanf("%d",&N);
	for(int i=1; i<=N; i++) scanf("%d%d",&A[i],&C[i]);
	for(int i=0; i<(1<<N); i++) P[i] = INF;
	for(int i=1; i<=N; i++) go(i, (1 << (i-1)));
	for(int i=1; i<(1<<N); i++) {
		D[i] = P[i];
		for(int j=i; j>0; j=((j-1)&i)) {
			D[i] = min(D[i], D[j] + D[i^j]);
		}
	}
	printf("%lld", D[(1<<N) - 1]);
	return 0;
}

Compilation message

telegraph.cpp: In function 'int main()':
telegraph.cpp:19:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&N);
  ~~~~~^~~~~~~~~
telegraph.cpp:20:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=1; i<=N; i++) scanf("%d%d",&A[i],&C[i]);
                          ~~~~~^~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -