# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1003590 | 2024-06-20T13:26:30 Z | aykhn | Subtree (INOI20_subtree) | C++17 | 42 ms | 24020 KB |
#include <bits/stdc++.h> using namespace std; #define int long long #define inf 0x3F3F3F3F3F3F3F3F const int MXN = 1e5 + 5; const int LOG = 20; const int mod = 1e9 + 7; vector<int> adj[MXN]; int p[MXN], used[MXN], down[MXN]; int in[MXN]; int dp[MXN]; void dfs(int a) { dp[a] = 0; used[a] = 1; for (int &v : adj[a]) { if (!used[v]) { p[v] = a; dfs(v); } else if (v != p[a]) { assert(!down[v]); down[v] = a; } } if (down[a]) { vector<int> path; int x = down[a]; while (x) { path.push_back(x); in[x] = 1; if (x == a) break; x = p[x]; } reverse(path.begin(), path.end()); vector<int> sum(path.size(), 0); int co = 1; for (int i = (int)path.size() - 1; i >= 0; i--) { if (i == (int)path.size() - 1) co = (co * dp[path[i]]) % mod; else { for (int &v : adj[path[i]]) { if (!in[v] && v != p[path[i]]) co = (co * dp[v]) % mod; } } sum[i] = ((i + 1 < path.size() ? sum[i + 1] : 0) + co) % mod; } co = 1; for (int i = 0; i + 1 < path.size(); i++) { for (int &v : adj[path[i]]) { if (!in[v] && v != p[path[i]]) { co = (co * (dp[v] + 1)) % mod; } } dp[a] = (dp[a] + co) % mod; if (i + 2 < path.size()) dp[a] = (dp[a] + ((sum[i + 2] * co) % mod)) % mod; } for (int x : path) in[x] = 0; } else { dp[a] = 1; for (int &v : adj[a]) { dp[a] = (dp[a] * (dp[v] + 1)) % mod; } } } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; for (int i = 1; i <= m; i++) { int u, v; cin >> u >> v; adj[u].push_back(v); adj[v].push_back(u); } dfs(1); int res = 0; for (int i = 1; i <= n; i++) { res = (res + dp[i]) % mod; } cout << res << '\n'; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 2648 KB | Output is correct |
2 | Correct | 1 ms | 2648 KB | Output is correct |
3 | Correct | 1 ms | 2652 KB | Output is correct |
4 | Correct | 1 ms | 2652 KB | Output is correct |
5 | Correct | 1 ms | 2648 KB | Output is correct |
6 | Correct | 1 ms | 2652 KB | Output is correct |
7 | Correct | 2 ms | 3016 KB | Output is correct |
8 | Correct | 1 ms | 2652 KB | Output is correct |
9 | Correct | 1 ms | 2652 KB | Output is correct |
10 | Correct | 1 ms | 2648 KB | Output is correct |
11 | Correct | 1 ms | 2652 KB | Output is correct |
12 | Correct | 1 ms | 2816 KB | Output is correct |
13 | Incorrect | 1 ms | 2808 KB | Output isn't correct |
14 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 2652 KB | Output is correct |
2 | Correct | 3 ms | 3420 KB | Output is correct |
3 | Correct | 29 ms | 10012 KB | Output is correct |
4 | Correct | 27 ms | 9820 KB | Output is correct |
5 | Correct | 28 ms | 9820 KB | Output is correct |
6 | Correct | 27 ms | 9808 KB | Output is correct |
7 | Correct | 42 ms | 21080 KB | Output is correct |
8 | Correct | 34 ms | 16980 KB | Output is correct |
9 | Correct | 32 ms | 16988 KB | Output is correct |
10 | Correct | 26 ms | 10576 KB | Output is correct |
11 | Correct | 23 ms | 9860 KB | Output is correct |
12 | Correct | 36 ms | 9308 KB | Output is correct |
13 | Correct | 30 ms | 9560 KB | Output is correct |
14 | Correct | 27 ms | 14536 KB | Output is correct |
15 | Correct | 35 ms | 22356 KB | Output is correct |
16 | Correct | 36 ms | 24020 KB | Output is correct |
17 | Correct | 28 ms | 9296 KB | Output is correct |
18 | Correct | 29 ms | 9548 KB | Output is correct |
19 | Correct | 38 ms | 9300 KB | Output is correct |
20 | Correct | 21 ms | 9924 KB | Output is correct |
21 | Correct | 23 ms | 10068 KB | Output is correct |
22 | Correct | 23 ms | 10072 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 2648 KB | Output is correct |
2 | Correct | 1 ms | 2648 KB | Output is correct |
3 | Correct | 1 ms | 2652 KB | Output is correct |
4 | Correct | 1 ms | 2652 KB | Output is correct |
5 | Correct | 1 ms | 2648 KB | Output is correct |
6 | Correct | 1 ms | 2652 KB | Output is correct |
7 | Correct | 2 ms | 3016 KB | Output is correct |
8 | Correct | 1 ms | 2652 KB | Output is correct |
9 | Correct | 1 ms | 2652 KB | Output is correct |
10 | Correct | 1 ms | 2648 KB | Output is correct |
11 | Correct | 1 ms | 2652 KB | Output is correct |
12 | Correct | 1 ms | 2816 KB | Output is correct |
13 | Incorrect | 1 ms | 2808 KB | Output isn't correct |
14 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 2648 KB | Output is correct |
2 | Correct | 1 ms | 2648 KB | Output is correct |
3 | Correct | 1 ms | 2652 KB | Output is correct |
4 | Correct | 1 ms | 2652 KB | Output is correct |
5 | Correct | 1 ms | 2648 KB | Output is correct |
6 | Correct | 1 ms | 2652 KB | Output is correct |
7 | Correct | 2 ms | 3016 KB | Output is correct |
8 | Correct | 1 ms | 2652 KB | Output is correct |
9 | Correct | 1 ms | 2652 KB | Output is correct |
10 | Correct | 1 ms | 2648 KB | Output is correct |
11 | Correct | 1 ms | 2652 KB | Output is correct |
12 | Correct | 1 ms | 2816 KB | Output is correct |
13 | Incorrect | 1 ms | 2808 KB | Output isn't correct |
14 | Halted | 0 ms | 0 KB | - |