Submission #48686545


Source Code Expand

// LUOGU_RID: 140389377
#include <bits/stdc++.h>
using namespace std; 
const int P = 1000000007; 

inline int poww(int a, int b) {
    int r = 1; 
    for (; b; b >>= 1, a = 1ll * a * a % P) if (b & 1) r = 1ll * r * a % P; 
    return r; 
}

int n, sz[200005], f[200005]; 
vector<int> G[200005]; 

void dfs(int x, int fa) {
    sz[x] = 1; 
    for (int y : G[x]) if (y != fa) dfs(y, x), sz[x] += sz[y]; 
    f[1] = 1ll * f[1] * sz[x] % P; 
}
void dfs2(int x, int fa) {
    for (int y : G[x]) if (y != fa) {
        f[y] = 1ll * f[x] * poww(sz[y], P - 2) % P * (n - sz[y]) % P; 
        dfs2(y, x); 
    }
}

int main(void) {
    ios::sync_with_stdio(0); 
    cin >> n; 
    for (int i = 1, u, v; i < n; ++i) 
        cin >> u >> v, 
        G[u].emplace_back(v), 
        G[v].emplace_back(u);
    f[1] = 1; dfs(1, 0); dfs2(1, 0); 
    int ans = 1; 
    for (int i = 2; i <= n; ++i) ans = 1ll * ans * i % P; 
    for (int i = 1; i <= n; ++i) cout << 1ll * ans * poww(f[i], P - 2) % P << "\n"; 
    return 0; 
}

Submission Info

Submission Time
Task F - Distributing Integers
User james1BadCreeper
Language C++ 17 (gcc 12.2)
Score 600
Code Size 1047 Byte
Status AC
Exec Time 143 ms
Memory 16608 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 4
AC × 18
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt
All line_01.txt, line_02_shuffled.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06_shuffled.txt, random_07_shuffled.txt, random_08_shuffled.txt, random_09_shuffled.txt, random_10.txt, sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt, star_01.txt, star_02_shuffled.txt
Case Name Status Exec Time Memory
line_01.txt AC 31 ms 13956 KiB
line_02_shuffled.txt AC 33 ms 12528 KiB
random_01.txt AC 134 ms 16108 KiB
random_02.txt AC 131 ms 16024 KiB
random_03.txt AC 134 ms 16132 KiB
random_04.txt AC 136 ms 16100 KiB
random_05.txt AC 128 ms 16156 KiB
random_06_shuffled.txt AC 143 ms 16032 KiB
random_07_shuffled.txt AC 136 ms 16228 KiB
random_08_shuffled.txt AC 141 ms 16084 KiB
random_09_shuffled.txt AC 133 ms 16228 KiB
random_10.txt AC 131 ms 16052 KiB
sample_01.txt AC 3 ms 8088 KiB
sample_02.txt AC 3 ms 8156 KiB
sample_03.txt AC 3 ms 8100 KiB
sample_04.txt AC 3 ms 8032 KiB
star_01.txt AC 93 ms 16608 KiB
star_02_shuffled.txt AC 110 ms 16392 KiB