結果
| 問題 |
No.812 Change of Class
|
| コンテスト | |
| ユーザー |
bal4u
|
| 提出日時 | 2019-07-13 18:43:59 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 118 ms / 4,000 ms |
| コード長 | 1,812 bytes |
| コンパイル時間 | 1,173 ms |
| コンパイル使用メモリ | 32,384 KB |
| 実行使用メモリ | 8,044 KB |
| 最終ジャッジ日時 | 2024-06-12 21:16:25 |
| 合計ジャッジ時間 | 4,494 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 60 |
コンパイルメッセージ
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:17:24: note: in expansion of macro 'gc'
17 | int n = 0, c = gc();
| ^~
main.c: In function 'out':
main.c:10:15: warning: implicit declaration of function 'putchar_unlocked' [-Wimplicit-function-declaration]
10 | #define pc(c) putchar_unlocked(c)
| ^~~~~~~~~~~~~~~~
main.c:26:17: note: in expansion of macro 'pc'
26 | if (!n) pc('0');
| ^~
ソースコード
// yukicoder: No.812 Change of Class
// 2019.7.13 bal4u
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif
int in() { // 非負整数の入力
int n = 0, c = gc();
do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
return n;
}
void out(int n) { // 非負整数の表示(出力)
int i;
char b[20];
if (!n) pc('0');
else {
i = 0; while (n) b[i++] = n % 10 + '0', n /= 10;
while (i--) pc(b[i]);
}
}
void outs(char *s) { while (*s) pc(*s++); }
#define QMAX 10000000
#define MAX 100005
typedef struct { int a, s; } Q;
Q que[QMAX+3]; int top, end;
int N;
int *to[MAX], hi[MAX];
char vis[MAX];
int calc(int n) {
int i = 0;
while (n) i++, n >>= 1;
return i;
}
int main()
{
int i, a, p, q, s, M, Q, ma;
int *memo, sz;
N = in(), M = in();
memo = malloc(sizeof(int)*M*2);
sz = 0; while (M--) {
p = in()-1, q = in()-1;
memo[sz++] = p, memo[sz++] = q;
hi[p]++, hi[q]++;
}
i = N; while (i--) if (hi[i]) to[i] = malloc(sizeof(int)*hi[i]);
memset(hi, 0, sizeof(int)*N);
i = 0; while (i < sz) {
p = memo[i++], q = memo[i++];
to[p][hi[p]++] = q, to[q][hi[q]++] = p;
}
// free(memo);
Q = in(); while (Q--) {
a = in()-1;
if (hi[a] == 0) { outs("0 0\n"); continue; }
que[0].a = a, que[0].s = 0, top = 0, end = 1, sz = ma = 0;
memset(vis, 0, N);
while (top != end) {
p = que[top].a, s = que[top].s;
if (++top == QMAX) top = 0;
if (s > ma) ma = s;
if (vis[p]) continue;
vis[p] = 1, sz++;
for (i = 0; i < hi[p]; i++) {
q = to[p][i];
if (!vis[q]) {
que[end].a = q, que[end].s = s+1;
if (++end == QMAX) end = 0;
}
}
}
out(sz-1), pc(' '), out(calc(ma-1)), pc('\n');
}
return 0;
}
bal4u