답안 #136310

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
136310 2019-07-25T06:21:33 Z 송준혁(#3262) Link (CEOI06_link) C++14
20 / 100
566 ms 15888 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;

int N, K, ans;
int M[505050];
int nx[505050], deg[505050];
priority_queue<pii> PQ;

void f(int u, int d){
	if (M[u] >= d) return;
	if (!M[u]) {
        deg[nx[u]]--;
        PQ.push(pii(-deg[nx[u]], nx[u]));
	}
	M[u] = d;
	f(nx[u], d-1);
}

int main(){
	scanf("%d %d", &N, &K);
	for (int i=1; i<=N; i++){
		int u, v;
		scanf("%d %d", &u, &v);
		nx[u] = v, deg[v]++;
	}
	for (int i=1; i<=N; i++) PQ.push(pii(-deg[i], i));
	f(1, K+1);
	while (!PQ.empty()){
		int u = PQ.top().second;
		PQ.pop();
		if (M[u]) continue;
		f(u, K);
		ans++;
	}
	printf("%d\n", ans);
	return 0;
}

Compilation message

link.cpp: In function 'int main()':
link.cpp:22:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &N, &K);
  ~~~~~^~~~~~~~~~~~~~~~~
link.cpp:25:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &u, &v);
   ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Incorrect 2 ms 376 KB Output isn't correct
4 Correct 3 ms 504 KB Output is correct
5 Incorrect 5 ms 504 KB Output isn't correct
6 Incorrect 22 ms 1368 KB Output isn't correct
7 Incorrect 34 ms 1648 KB Output isn't correct
8 Incorrect 50 ms 2284 KB Output isn't correct
9 Correct 73 ms 4972 KB Output is correct
10 Incorrect 68 ms 2716 KB Output isn't correct
11 Correct 113 ms 5016 KB Output is correct
12 Incorrect 168 ms 4812 KB Output isn't correct
13 Incorrect 214 ms 8352 KB Output isn't correct
14 Incorrect 272 ms 6920 KB Output isn't correct
15 Correct 316 ms 9436 KB Output is correct
16 Incorrect 402 ms 9180 KB Output isn't correct
17 Incorrect 445 ms 15324 KB Output isn't correct
18 Incorrect 490 ms 14556 KB Output isn't correct
19 Incorrect 495 ms 15000 KB Output isn't correct
20 Incorrect 511 ms 15576 KB Output isn't correct
21 Incorrect 526 ms 15452 KB Output isn't correct
22 Incorrect 486 ms 15768 KB Output isn't correct
23 Incorrect 566 ms 15804 KB Output isn't correct
24 Incorrect 505 ms 15836 KB Output isn't correct
25 Incorrect 501 ms 15888 KB Output isn't correct