Submission #1003160

# Submission time Handle Problem Language Result Execution time Memory
1003160 2024-06-20T07:00:40 Z vjudge1 Subtree (INOI20_subtree) C++17
20 / 100
778 ms 1048576 KB
#include <bits/stdc++.h>
using namespace std;
int n, m;
namespace SUBT1 {
  const int N = 1e5+10;
  vector<int> g[N];
  struct DSU {
    vector<int> e;
    DSU(int n) {
      e=vector<int>(n+1, -1);
    }
    int get(int x) {
      if(e[x] < 0)return x;
      return e[x] = get(e[x]);
    }
    int sz(int x) {
      return -e[get(x)];
    }
    bool unite(int a, int b) {
      a=get(a),b=get(b);
      if(a == b)return false;
      if(-e[a] > -e[b]) {
        swap(a,b);
      }
      e[b]+=e[a];
      e[a] = b;
      return true;
    }
  };
  void solve() {
    cin >> m;
    for(int i  = 0;i<m;i++) {
      int u, v;
      cin >> u >> v;
      u--,v--;
      g[u].push_back(v);
    }
    int ans=0;
    for(int mask = 1;mask<(1<<n);mask++) {
      DSU d(n);
      int cnt=0;
      int f=-1, sz=0;
      for(int j = 0;j<n;j++) {
        if(mask&(1<<j)) {
          sz++;
          f=j;
          for(int to:g[j]){
            if(mask&(1<<to)) {
              d.unite(to, j);
              cnt++;
            }
          }
        }
      }
      if(d.sz(f) == sz and cnt==sz-1){
        ans++;
      }
    }
    cout << ans <<"\n";
  }
}
namespace SUBT2 {
  const int N = 1e5+10;
  const long long mod = 1e9+7;
  long long dp[N];
  long long ans=0;
  vector<int> g[N];
  void dfs(int at, int p) {
    dp[at]=1;
    long long res=1;
    for(int to:g[at]) {
      if(to==p)continue;
      dfs(to,at);
      res*=dp[to];
      res%=mod;
    }
    dp[at]=res;
    ans+=dp[at];
    dp[at]++;
    ans%=mod;
  }
  void solve() {
    cin >> m;
    for(int i = 0;i<m;i++) {
      int u, v;
      cin >> u >> v;
      g[u].push_back(v);
      g[v].push_back(u);
    }
    dfs(1, 0);
    cout << ans << "\n";
  }
};
int main () {
  cin.tie(0)->sync_with_stdio(0);
  cin >> n;
  if(n <= 20) {
    SUBT1::solve();
  }
  else {
    SUBT2::solve();
  }
}

# Verdict Execution time Memory Grader output
1 Correct 2 ms 5720 KB Output is correct
2 Correct 2 ms 5724 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 2 ms 5936 KB Output is correct
5 Correct 2 ms 5724 KB Output is correct
6 Correct 2 ms 5084 KB Output is correct
7 Correct 3 ms 5724 KB Output is correct
8 Correct 128 ms 5724 KB Output is correct
9 Correct 98 ms 4956 KB Output is correct
10 Correct 101 ms 5724 KB Output is correct
11 Correct 106 ms 4956 KB Output is correct
12 Correct 49 ms 5724 KB Output is correct
13 Correct 101 ms 5724 KB Output is correct
14 Correct 50 ms 4956 KB Output is correct
15 Correct 52 ms 4956 KB Output is correct
16 Correct 100 ms 4952 KB Output is correct
17 Correct 43 ms 5920 KB Output is correct
18 Correct 51 ms 5724 KB Output is correct
19 Correct 51 ms 5724 KB Output is correct
20 Correct 107 ms 5136 KB Output is correct
21 Correct 102 ms 5724 KB Output is correct
22 Correct 51 ms 5140 KB Output is correct
23 Correct 98 ms 4956 KB Output is correct
24 Correct 49 ms 4956 KB Output is correct
25 Correct 2 ms 4956 KB Output is correct
26 Correct 2 ms 4956 KB Output is correct
27 Correct 2 ms 5160 KB Output is correct
28 Correct 5 ms 4956 KB Output is correct
29 Correct 49 ms 5140 KB Output is correct
30 Correct 102 ms 5140 KB Output is correct
31 Correct 53 ms 4952 KB Output is correct
32 Correct 49 ms 4952 KB Output is correct
33 Correct 52 ms 4956 KB Output is correct
34 Correct 96 ms 4956 KB Output is correct
35 Correct 105 ms 5920 KB Output is correct
36 Correct 99 ms 5724 KB Output is correct
37 Correct 109 ms 5720 KB Output is correct
38 Correct 99 ms 5724 KB Output is correct
39 Correct 102 ms 4952 KB Output is correct
40 Correct 97 ms 4952 KB Output is correct
41 Correct 108 ms 5724 KB Output is correct
42 Correct 50 ms 5724 KB Output is correct
43 Correct 49 ms 4952 KB Output is correct
44 Correct 101 ms 5136 KB Output is correct
45 Correct 110 ms 4956 KB Output is correct
46 Correct 113 ms 4956 KB Output is correct
47 Correct 103 ms 4956 KB Output is correct
48 Correct 98 ms 4956 KB Output is correct
49 Correct 102 ms 4952 KB Output is correct
50 Correct 101 ms 4952 KB Output is correct
51 Correct 104 ms 4956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 4 ms 5468 KB Output is correct
3 Correct 24 ms 10268 KB Output is correct
4 Correct 22 ms 10328 KB Output is correct
5 Correct 24 ms 10332 KB Output is correct
6 Correct 23 ms 10328 KB Output is correct
7 Correct 32 ms 15700 KB Output is correct
8 Correct 28 ms 13764 KB Output is correct
9 Correct 29 ms 13660 KB Output is correct
10 Correct 31 ms 10768 KB Output is correct
11 Correct 20 ms 10468 KB Output is correct
12 Correct 31 ms 10064 KB Output is correct
13 Correct 25 ms 10076 KB Output is correct
14 Correct 22 ms 12756 KB Output is correct
15 Correct 33 ms 16724 KB Output is correct
16 Correct 28 ms 17500 KB Output is correct
17 Correct 26 ms 10216 KB Output is correct
18 Correct 25 ms 10076 KB Output is correct
19 Correct 32 ms 10076 KB Output is correct
20 Correct 21 ms 10444 KB Output is correct
21 Correct 21 ms 10720 KB Output is correct
22 Correct 22 ms 10516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 5720 KB Output is correct
2 Correct 2 ms 5724 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 2 ms 5936 KB Output is correct
5 Correct 2 ms 5724 KB Output is correct
6 Correct 2 ms 5084 KB Output is correct
7 Correct 3 ms 5724 KB Output is correct
8 Correct 128 ms 5724 KB Output is correct
9 Correct 98 ms 4956 KB Output is correct
10 Correct 101 ms 5724 KB Output is correct
11 Correct 106 ms 4956 KB Output is correct
12 Correct 49 ms 5724 KB Output is correct
13 Correct 101 ms 5724 KB Output is correct
14 Correct 50 ms 4956 KB Output is correct
15 Correct 52 ms 4956 KB Output is correct
16 Correct 100 ms 4952 KB Output is correct
17 Correct 43 ms 5920 KB Output is correct
18 Correct 51 ms 5724 KB Output is correct
19 Correct 51 ms 5724 KB Output is correct
20 Correct 107 ms 5136 KB Output is correct
21 Correct 102 ms 5724 KB Output is correct
22 Correct 51 ms 5140 KB Output is correct
23 Correct 98 ms 4956 KB Output is correct
24 Correct 49 ms 4956 KB Output is correct
25 Correct 2 ms 4956 KB Output is correct
26 Correct 2 ms 4956 KB Output is correct
27 Correct 2 ms 5160 KB Output is correct
28 Correct 5 ms 4956 KB Output is correct
29 Correct 49 ms 5140 KB Output is correct
30 Correct 102 ms 5140 KB Output is correct
31 Correct 53 ms 4952 KB Output is correct
32 Correct 49 ms 4952 KB Output is correct
33 Correct 52 ms 4956 KB Output is correct
34 Correct 96 ms 4956 KB Output is correct
35 Correct 105 ms 5920 KB Output is correct
36 Correct 99 ms 5724 KB Output is correct
37 Correct 109 ms 5720 KB Output is correct
38 Correct 99 ms 5724 KB Output is correct
39 Correct 102 ms 4952 KB Output is correct
40 Correct 97 ms 4952 KB Output is correct
41 Correct 108 ms 5724 KB Output is correct
42 Correct 50 ms 5724 KB Output is correct
43 Correct 49 ms 4952 KB Output is correct
44 Correct 101 ms 5136 KB Output is correct
45 Correct 110 ms 4956 KB Output is correct
46 Correct 113 ms 4956 KB Output is correct
47 Correct 103 ms 4956 KB Output is correct
48 Correct 98 ms 4956 KB Output is correct
49 Correct 102 ms 4952 KB Output is correct
50 Correct 101 ms 4952 KB Output is correct
51 Correct 104 ms 4956 KB Output is correct
52 Runtime error 778 ms 1048576 KB Execution killed with signal 9
53 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 5720 KB Output is correct
2 Correct 2 ms 5724 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 2 ms 5936 KB Output is correct
5 Correct 2 ms 5724 KB Output is correct
6 Correct 2 ms 5084 KB Output is correct
7 Correct 3 ms 5724 KB Output is correct
8 Correct 128 ms 5724 KB Output is correct
9 Correct 98 ms 4956 KB Output is correct
10 Correct 101 ms 5724 KB Output is correct
11 Correct 106 ms 4956 KB Output is correct
12 Correct 49 ms 5724 KB Output is correct
13 Correct 101 ms 5724 KB Output is correct
14 Correct 50 ms 4956 KB Output is correct
15 Correct 52 ms 4956 KB Output is correct
16 Correct 100 ms 4952 KB Output is correct
17 Correct 43 ms 5920 KB Output is correct
18 Correct 51 ms 5724 KB Output is correct
19 Correct 51 ms 5724 KB Output is correct
20 Correct 107 ms 5136 KB Output is correct
21 Correct 102 ms 5724 KB Output is correct
22 Correct 51 ms 5140 KB Output is correct
23 Correct 98 ms 4956 KB Output is correct
24 Correct 49 ms 4956 KB Output is correct
25 Correct 2 ms 4956 KB Output is correct
26 Correct 2 ms 4956 KB Output is correct
27 Correct 2 ms 5160 KB Output is correct
28 Correct 5 ms 4956 KB Output is correct
29 Correct 49 ms 5140 KB Output is correct
30 Correct 102 ms 5140 KB Output is correct
31 Correct 53 ms 4952 KB Output is correct
32 Correct 49 ms 4952 KB Output is correct
33 Correct 52 ms 4956 KB Output is correct
34 Correct 96 ms 4956 KB Output is correct
35 Correct 105 ms 5920 KB Output is correct
36 Correct 99 ms 5724 KB Output is correct
37 Correct 109 ms 5720 KB Output is correct
38 Correct 99 ms 5724 KB Output is correct
39 Correct 102 ms 4952 KB Output is correct
40 Correct 97 ms 4952 KB Output is correct
41 Correct 108 ms 5724 KB Output is correct
42 Correct 50 ms 5724 KB Output is correct
43 Correct 49 ms 4952 KB Output is correct
44 Correct 101 ms 5136 KB Output is correct
45 Correct 110 ms 4956 KB Output is correct
46 Correct 113 ms 4956 KB Output is correct
47 Correct 103 ms 4956 KB Output is correct
48 Correct 98 ms 4956 KB Output is correct
49 Correct 102 ms 4952 KB Output is correct
50 Correct 101 ms 4952 KB Output is correct
51 Correct 104 ms 4956 KB Output is correct
52 Correct 2 ms 4956 KB Output is correct
53 Correct 4 ms 5468 KB Output is correct
54 Correct 24 ms 10268 KB Output is correct
55 Correct 22 ms 10328 KB Output is correct
56 Correct 24 ms 10332 KB Output is correct
57 Correct 23 ms 10328 KB Output is correct
58 Correct 32 ms 15700 KB Output is correct
59 Correct 28 ms 13764 KB Output is correct
60 Correct 29 ms 13660 KB Output is correct
61 Correct 31 ms 10768 KB Output is correct
62 Correct 20 ms 10468 KB Output is correct
63 Correct 31 ms 10064 KB Output is correct
64 Correct 25 ms 10076 KB Output is correct
65 Correct 22 ms 12756 KB Output is correct
66 Correct 33 ms 16724 KB Output is correct
67 Correct 28 ms 17500 KB Output is correct
68 Correct 26 ms 10216 KB Output is correct
69 Correct 25 ms 10076 KB Output is correct
70 Correct 32 ms 10076 KB Output is correct
71 Correct 21 ms 10444 KB Output is correct
72 Correct 21 ms 10720 KB Output is correct
73 Correct 22 ms 10516 KB Output is correct
74 Runtime error 778 ms 1048576 KB Execution killed with signal 9
75 Halted 0 ms 0 KB -