답안 #1003159

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1003159 2024-06-20T07:00:06 Z vjudge1 Subtree (INOI20_subtree) C++17
8 / 100
617 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]++;
  }
  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();
  }
}

# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 2 ms 4952 KB Output is correct
3 Correct 2 ms 4952 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 2 ms 4956 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 2 ms 4952 KB Output is correct
8 Correct 110 ms 4952 KB Output is correct
9 Correct 99 ms 5140 KB Output is correct
10 Correct 101 ms 4952 KB Output is correct
11 Correct 116 ms 4956 KB Output is correct
12 Correct 59 ms 4952 KB Output is correct
13 Correct 107 ms 5136 KB Output is correct
14 Correct 50 ms 4956 KB Output is correct
15 Correct 52 ms 5144 KB Output is correct
16 Correct 100 ms 5140 KB Output is correct
17 Correct 47 ms 4952 KB Output is correct
18 Correct 54 ms 5136 KB Output is correct
19 Correct 52 ms 4968 KB Output is correct
20 Correct 109 ms 4956 KB Output is correct
21 Correct 107 ms 4956 KB Output is correct
22 Correct 51 ms 4952 KB Output is correct
23 Correct 99 ms 4956 KB Output is correct
24 Correct 48 ms 4956 KB Output is correct
25 Correct 2 ms 4952 KB Output is correct
26 Correct 2 ms 4956 KB Output is correct
27 Correct 2 ms 4956 KB Output is correct
28 Correct 5 ms 5160 KB Output is correct
29 Correct 51 ms 4952 KB Output is correct
30 Correct 111 ms 4956 KB Output is correct
31 Correct 72 ms 5140 KB Output is correct
32 Correct 50 ms 5136 KB Output is correct
33 Correct 52 ms 4952 KB Output is correct
34 Correct 119 ms 5140 KB Output is correct
35 Correct 108 ms 4956 KB Output is correct
36 Correct 111 ms 4956 KB Output is correct
37 Correct 111 ms 4956 KB Output is correct
38 Correct 100 ms 4956 KB Output is correct
39 Correct 106 ms 5140 KB Output is correct
40 Correct 102 ms 5208 KB Output is correct
41 Correct 105 ms 4952 KB Output is correct
42 Correct 62 ms 4956 KB Output is correct
43 Correct 49 ms 4952 KB Output is correct
44 Correct 103 ms 5136 KB Output is correct
45 Correct 114 ms 4956 KB Output is correct
46 Correct 106 ms 4956 KB Output is correct
47 Correct 103 ms 4956 KB Output is correct
48 Correct 100 ms 4956 KB Output is correct
49 Correct 99 ms 4956 KB Output is correct
50 Correct 106 ms 4956 KB Output is correct
51 Correct 103 ms 4956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 4952 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 2 ms 4952 KB Output is correct
3 Correct 2 ms 4952 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 2 ms 4956 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 2 ms 4952 KB Output is correct
8 Correct 110 ms 4952 KB Output is correct
9 Correct 99 ms 5140 KB Output is correct
10 Correct 101 ms 4952 KB Output is correct
11 Correct 116 ms 4956 KB Output is correct
12 Correct 59 ms 4952 KB Output is correct
13 Correct 107 ms 5136 KB Output is correct
14 Correct 50 ms 4956 KB Output is correct
15 Correct 52 ms 5144 KB Output is correct
16 Correct 100 ms 5140 KB Output is correct
17 Correct 47 ms 4952 KB Output is correct
18 Correct 54 ms 5136 KB Output is correct
19 Correct 52 ms 4968 KB Output is correct
20 Correct 109 ms 4956 KB Output is correct
21 Correct 107 ms 4956 KB Output is correct
22 Correct 51 ms 4952 KB Output is correct
23 Correct 99 ms 4956 KB Output is correct
24 Correct 48 ms 4956 KB Output is correct
25 Correct 2 ms 4952 KB Output is correct
26 Correct 2 ms 4956 KB Output is correct
27 Correct 2 ms 4956 KB Output is correct
28 Correct 5 ms 5160 KB Output is correct
29 Correct 51 ms 4952 KB Output is correct
30 Correct 111 ms 4956 KB Output is correct
31 Correct 72 ms 5140 KB Output is correct
32 Correct 50 ms 5136 KB Output is correct
33 Correct 52 ms 4952 KB Output is correct
34 Correct 119 ms 5140 KB Output is correct
35 Correct 108 ms 4956 KB Output is correct
36 Correct 111 ms 4956 KB Output is correct
37 Correct 111 ms 4956 KB Output is correct
38 Correct 100 ms 4956 KB Output is correct
39 Correct 106 ms 5140 KB Output is correct
40 Correct 102 ms 5208 KB Output is correct
41 Correct 105 ms 4952 KB Output is correct
42 Correct 62 ms 4956 KB Output is correct
43 Correct 49 ms 4952 KB Output is correct
44 Correct 103 ms 5136 KB Output is correct
45 Correct 114 ms 4956 KB Output is correct
46 Correct 106 ms 4956 KB Output is correct
47 Correct 103 ms 4956 KB Output is correct
48 Correct 100 ms 4956 KB Output is correct
49 Correct 99 ms 4956 KB Output is correct
50 Correct 106 ms 4956 KB Output is correct
51 Correct 103 ms 4956 KB Output is correct
52 Runtime error 617 ms 1048576 KB Execution killed with signal 9
53 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 2 ms 4952 KB Output is correct
3 Correct 2 ms 4952 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 2 ms 4956 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 2 ms 4952 KB Output is correct
8 Correct 110 ms 4952 KB Output is correct
9 Correct 99 ms 5140 KB Output is correct
10 Correct 101 ms 4952 KB Output is correct
11 Correct 116 ms 4956 KB Output is correct
12 Correct 59 ms 4952 KB Output is correct
13 Correct 107 ms 5136 KB Output is correct
14 Correct 50 ms 4956 KB Output is correct
15 Correct 52 ms 5144 KB Output is correct
16 Correct 100 ms 5140 KB Output is correct
17 Correct 47 ms 4952 KB Output is correct
18 Correct 54 ms 5136 KB Output is correct
19 Correct 52 ms 4968 KB Output is correct
20 Correct 109 ms 4956 KB Output is correct
21 Correct 107 ms 4956 KB Output is correct
22 Correct 51 ms 4952 KB Output is correct
23 Correct 99 ms 4956 KB Output is correct
24 Correct 48 ms 4956 KB Output is correct
25 Correct 2 ms 4952 KB Output is correct
26 Correct 2 ms 4956 KB Output is correct
27 Correct 2 ms 4956 KB Output is correct
28 Correct 5 ms 5160 KB Output is correct
29 Correct 51 ms 4952 KB Output is correct
30 Correct 111 ms 4956 KB Output is correct
31 Correct 72 ms 5140 KB Output is correct
32 Correct 50 ms 5136 KB Output is correct
33 Correct 52 ms 4952 KB Output is correct
34 Correct 119 ms 5140 KB Output is correct
35 Correct 108 ms 4956 KB Output is correct
36 Correct 111 ms 4956 KB Output is correct
37 Correct 111 ms 4956 KB Output is correct
38 Correct 100 ms 4956 KB Output is correct
39 Correct 106 ms 5140 KB Output is correct
40 Correct 102 ms 5208 KB Output is correct
41 Correct 105 ms 4952 KB Output is correct
42 Correct 62 ms 4956 KB Output is correct
43 Correct 49 ms 4952 KB Output is correct
44 Correct 103 ms 5136 KB Output is correct
45 Correct 114 ms 4956 KB Output is correct
46 Correct 106 ms 4956 KB Output is correct
47 Correct 103 ms 4956 KB Output is correct
48 Correct 100 ms 4956 KB Output is correct
49 Correct 99 ms 4956 KB Output is correct
50 Correct 106 ms 4956 KB Output is correct
51 Correct 103 ms 4956 KB Output is correct
52 Incorrect 2 ms 4952 KB Output isn't correct
53 Halted 0 ms 0 KB -