結果
| 問題 |
No.679 不思議マーケット
|
| コンテスト | |
| ユーザー |
bal4u
|
| 提出日時 | 2019-07-29 20:36:41 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 1,201 bytes |
| コンパイル時間 | 267 ms |
| コンパイル使用メモリ | 30,464 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-02 15:27:30 |
| 合計ジャッジ時間 | 1,080 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 18 |
コンパイルメッセージ
main.c: In function 'in':
main.c:9:14: warning: implicit declaration of function 'getchar_unlocked' [-Wimplicit-function-declaration]
9 | #define gc() getchar_unlocked()
| ^~~~~~~~~~~~~~~~
main.c:15:24: note: in expansion of macro 'gc'
15 | int n = 0, c = gc();
| ^~
ソースコード
// yukicoder: No.679 不思議マーケット
// 2019.7.29 bal4u
#include <stdio.h>
//#include <stdlib.h>
//#include <string.h>
#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif
int in() { // 非負整数の入力
int n = 0, c = gc();
do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
return n;
}
// トポロジーソート
#define TMAX 505
int t_hi[TMAX], t_to[TMAX][TMAX]; // トポロジーソートのための有向グラフ構造
int t_ans[TMAX]; // トポロジーソートの結果。後ろのほうが指されたもの。
int topoSort(int V) {
int i, j, k, sz;
static int q[TMAX], top, end;
static int count[TMAX];
for (i = 0; i < V; i++) for (j = 0; j < t_hi[i]; j++) count[t_to[i][j]]++;
top = end = 0;
for (i = 0; i < V; i++) if (!count[i]) q[end++] = i;
sz = 0; while (top < end) {
t_ans[sz++] = i = q[top++];
for (j = 0; j < t_hi[i]; j++) {
k = t_to[i][j];
if (--count[k] == 0) q[end++] = k;
}
}
return sz;
}
int main()
{
int i, k, h, n, m;
n = in(), m = in();
while (m--) {
int g = in()-1, r = in();
while (r--) h = in()-1, t_to[h][t_hi[h]++] = g;
}
printf("%d\n", topoSort(n));
return 0;
}
bal4u