From cdd508634597894a5378eeffd3d064ac9d37572b Mon Sep 17 00:00:00 2001 From: Ren Baoshuo Date: Wed, 21 Jul 2021 00:38:07 +0800 Subject: [PATCH] =?UTF-8?q?P1144=20=E6=9C=80=E7=9F=AD=E8=B7=AF=E8=AE=A1?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit R53741486 --- Luogu/problem/P1144/P1144.cpp | 41 +++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 Luogu/problem/P1144/P1144.cpp diff --git a/Luogu/problem/P1144/P1144.cpp b/Luogu/problem/P1144/P1144.cpp new file mode 100644 index 00000000..5b14833f --- /dev/null +++ b/Luogu/problem/P1144/P1144.cpp @@ -0,0 +1,41 @@ +#include + +using namespace std; + +const int mod = 100003; + +int n, m, x, y, depth[1000005], cnt[1000005]; +vector g[1000005]; +bool vis[1000005]; + +int main() { + cin >> n >> m; + for (int i = 1; i <= m; i++) { + cin >> x >> y; + g[x].push_back(y); + g[y].push_back(x); + } + queue q; + depth[1] = 0; + cnt[1] = 1; + q.push(1); + vis[1] = true; + while (!q.empty()) { + int t = q.front(); + q.pop(); + for (int i : g[t]) { + if (!vis[i]) { + vis[i] = true; + depth[i] = depth[t] + 1; + q.push(i); + } + if (depth[i] == depth[t] + 1) { + cnt[i] = (cnt[i] + cnt[t]) % mod; + } + } + } + for (int i = 1; i <= n; i++) { + cout << cnt[i] % mod << endl; + } + return 0; +}