結果
| 問題 |
No.3309 Aging Railway
|
| コンテスト | |
| ユーザー |
pengin_2000
|
| 提出日時 | 2025-10-24 21:46:02 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 195 ms / 3,000 ms |
| コード長 | 1,089 bytes |
| コンパイル時間 | 362 ms |
| コンパイル使用メモリ | 27,728 KB |
| 実行使用メモリ | 7,716 KB |
| 最終ジャッジ日時 | 2025-10-24 21:46:06 |
| 合計ジャッジ時間 | 4,320 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 20 |
コンパイルメッセージ
main.c: In function ‘main’:
main.c:9:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
9 | scanf("%d %d", &n, &m);
| ^~~~~~~~~~~~~~~~~~~~~~
main.c:13:17: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
13 | scanf("%d %d", &u[i], &v[i]);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.c:44:17: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
44 | scanf("%d %d", &s, &t);
| ^~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include<stdio.h>
int u[6003], v[6003];
int par[3003], depth[3003], par_id[3003];
int stack[3003], ss;
int ans[3003];
int main()
{
int n, m;
scanf("%d %d", &n, &m);
int i, j;
for (i = 0; i < n - 1; i++)
{
scanf("%d %d", &u[i], &v[i]);
u[i + n - 1] = --v[i];
v[i + n - 1] = --u[i];
}
for (i = 0; i < n; i++)
par[i] = -1;
par[0] = 0;
depth[0] = 0;
stack[0] = 0;
ss = 1;
while (ss > 0)
{
i = stack[--ss];
for (j = 0; j < 2 * n - 2; j++)
{
if (u[j] != i)
continue;
if (par[v[j]] < 0)
{
par[v[j]] = i;
par_id[v[j]] = j % (n - 1);
depth[v[j]] = depth[i] + 1;
stack[ss++] = v[j];
}
}
}
for (i = 0; i < n; i++)
ans[i] = 0;
int s, t, res;
for (; m > 0; m--)
{
scanf("%d %d", &s, &t);
s--;
t--;
res = n;
while (s != t)
{
if (depth[s] < depth[t])
{
if (res > par_id[t])
res = par_id[t];
t = par[t];
}
else
{
if (res > par_id[s])
res = par_id[s];
s = par[s];
}
}
for (j = 0; j < res; j++)
ans[j]++;
}
for (i = 0; i < n - 1; i++)
printf("%d\n", ans[i]);
return 0;
}
pengin_2000