Submission #1003249

# Submission time Handle Problem Language Result Execution time Memory
1003249 2024-06-20T08:11:35 Z vjudge1 Subtree (INOI20_subtree) C++17
20 / 100
2000 ms 29952 KB
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+10;
vector<int> g[N];
vector<int> bridges[N];
vector<int> notBridges[N];
int add[N], depth[N];
bool vis[N];
vector<vector<int>> cycles;
int getCycle[N];
void dfsAdd(int at, int p) {
  vis[at]=1;
  for(int to:g[at]) {
    if(to==p)continue;
    if(vis[to] == 1) 
    {
      if(depth[at] > depth[to]) {
        add[at]++;
        add[to]--;
        notBridges[to].push_back(at);
        notBridges[at].push_back(to);
      }
      continue;
    }
    depth[to]=depth[at]+1;
    dfsAdd(to, at);
  }
}
void dfsGetBridges(int at, int p) {
  vis[at]=1;
  for(int to:g[at]) {
    if(vis[to])continue;
    dfsGetBridges(to, at);
    add[at]+=add[to];
  }
  if(p==0)return;
  if(add[at] == 0) {
    bridges[at].push_back(p);
    bridges[p].push_back(at);
  }
  else {
    notBridges[at].push_back(p);
    notBridges[p].push_back(at);
  }
}
vector<int> tempcycle;
void dfsGetCycles(int at) {
  tempcycle.push_back(at);
  vis[at]=1;
  for(int to:notBridges[at]) {
    if(vis[to])continue;
    dfsGetCycles(to);
  }
}
long long dp[N], tmpdp[N];
const long long mod = 1e9+7;
long long ans=0;
void dfsCalc(int c) {
  vis[c]=1;
  for(int at:cycles[c]) {
    dp[at]=1;
    for(int to:g[at]) {
      if(!vis[getCycle[to]]) {
        dfsCalc(getCycle[to]);
        dp[at] = (dp[at]*(dp[to]+1))%mod;
      }
    }
  }
  if(cycles[c].size()==1){
    ans+=dp[cycles[c][0]];
    ans%=mod;
    return;
  }
  for(int i = 0;i<cycles[c].size();i++) {
    for(int j = 0;j<cycles[c].size();j++) {
      long long prod = dp[cycles[c][j]];
      int sz=1;
      for(int k = i;k!=j;k=(k+1)%cycles[c].size()){
        prod=(prod*dp[cycles[c][k]])%mod;
        sz++;
      }
      if(sz==cycles[c].size())continue;
      ans+=prod;
      ans%=mod;
      for(int k = i;k!=j;k=(k+1)%cycles[c].size()) {
        tmpdp[cycles[c][k]]+=prod;
        tmpdp[cycles[c][k]]%=mod;
      }
      tmpdp[cycles[c][j]]+=prod;
      tmpdp[cycles[c][j]]%=mod;
    }
  }
  for(int i:cycles[c]) {
    dp[i]=tmpdp[i];
    ans%=mod;
  }
}
int main () {
  cin.tie(0)->sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  for(int i = 0;i<m;i++) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfsAdd(1, 0);
  memset(vis, 0, sizeof vis);
  dfsGetBridges(1, 0);
  memset(vis, 0, sizeof vis);
  for(int i = 1;i<=n;i++) {
    if(vis[i] == 0) {
      dfsGetCycles(i);
      for(int c:tempcycle) {
        getCycle[c] = cycles.size();
      }
      cycles.push_back(tempcycle);
      tempcycle.clear();
    }
  }
  memset(vis, 0, sizeof vis);
  dfsCalc(0);
  cout << ans%mod << "\n";
}

Compilation message

Main.cpp: In function 'void dfsCalc(int)':
Main.cpp:74:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |   for(int i = 0;i<cycles[c].size();i++) {
      |                 ~^~~~~~~~~~~~~~~~~
Main.cpp:75:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |     for(int j = 0;j<cycles[c].size();j++) {
      |                   ~^~~~~~~~~~~~~~~~~
Main.cpp:82:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |       if(sz==cycles[c].size())continue;
      |          ~~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7516 KB Output is correct
2 Correct 3 ms 7516 KB Output is correct
3 Correct 4 ms 7428 KB Output is correct
4 Correct 3 ms 7516 KB Output is correct
5 Correct 3 ms 7516 KB Output is correct
6 Correct 3 ms 7584 KB Output is correct
7 Correct 4 ms 7516 KB Output is correct
8 Correct 3 ms 7516 KB Output is correct
9 Correct 3 ms 7588 KB Output is correct
10 Correct 3 ms 7516 KB Output is correct
11 Correct 3 ms 7516 KB Output is correct
12 Correct 3 ms 7516 KB Output is correct
13 Correct 3 ms 7516 KB Output is correct
14 Correct 3 ms 7512 KB Output is correct
15 Correct 3 ms 7516 KB Output is correct
16 Correct 3 ms 7512 KB Output is correct
17 Correct 3 ms 7516 KB Output is correct
18 Correct 4 ms 7516 KB Output is correct
19 Correct 3 ms 7516 KB Output is correct
20 Correct 3 ms 7516 KB Output is correct
21 Correct 4 ms 7516 KB Output is correct
22 Correct 3 ms 7516 KB Output is correct
23 Correct 3 ms 7628 KB Output is correct
24 Correct 3 ms 7516 KB Output is correct
25 Correct 3 ms 7516 KB Output is correct
26 Correct 3 ms 7516 KB Output is correct
27 Correct 3 ms 7516 KB Output is correct
28 Correct 3 ms 7472 KB Output is correct
29 Correct 3 ms 7516 KB Output is correct
30 Correct 3 ms 7628 KB Output is correct
31 Correct 3 ms 7516 KB Output is correct
32 Correct 3 ms 7516 KB Output is correct
33 Correct 3 ms 7516 KB Output is correct
34 Correct 3 ms 7416 KB Output is correct
35 Correct 4 ms 7516 KB Output is correct
36 Correct 3 ms 7516 KB Output is correct
37 Correct 4 ms 7628 KB Output is correct
38 Correct 4 ms 7468 KB Output is correct
39 Correct 3 ms 7512 KB Output is correct
40 Correct 3 ms 7512 KB Output is correct
41 Correct 3 ms 7588 KB Output is correct
42 Correct 3 ms 7516 KB Output is correct
43 Correct 3 ms 7516 KB Output is correct
44 Correct 3 ms 7768 KB Output is correct
45 Correct 3 ms 7516 KB Output is correct
46 Correct 3 ms 7516 KB Output is correct
47 Correct 3 ms 7516 KB Output is correct
48 Correct 3 ms 7516 KB Output is correct
49 Correct 4 ms 7516 KB Output is correct
50 Correct 3 ms 7516 KB Output is correct
51 Correct 3 ms 7516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7512 KB Output is correct
2 Correct 8 ms 8852 KB Output is correct
3 Correct 53 ms 21504 KB Output is correct
4 Correct 55 ms 21372 KB Output is correct
5 Correct 58 ms 21280 KB Output is correct
6 Correct 54 ms 21508 KB Output is correct
7 Correct 90 ms 27904 KB Output is correct
8 Correct 66 ms 25584 KB Output is correct
9 Correct 62 ms 25604 KB Output is correct
10 Correct 53 ms 22272 KB Output is correct
11 Correct 45 ms 21820 KB Output is correct
12 Correct 64 ms 21248 KB Output is correct
13 Correct 64 ms 21248 KB Output is correct
14 Correct 52 ms 24628 KB Output is correct
15 Correct 74 ms 29184 KB Output is correct
16 Correct 69 ms 29952 KB Output is correct
17 Correct 64 ms 21168 KB Output is correct
18 Correct 76 ms 21252 KB Output is correct
19 Correct 67 ms 21248 KB Output is correct
20 Correct 43 ms 21568 KB Output is correct
21 Correct 45 ms 21712 KB Output is correct
22 Correct 55 ms 21540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7516 KB Output is correct
2 Correct 3 ms 7516 KB Output is correct
3 Correct 4 ms 7428 KB Output is correct
4 Correct 3 ms 7516 KB Output is correct
5 Correct 3 ms 7516 KB Output is correct
6 Correct 3 ms 7584 KB Output is correct
7 Correct 4 ms 7516 KB Output is correct
8 Correct 3 ms 7516 KB Output is correct
9 Correct 3 ms 7588 KB Output is correct
10 Correct 3 ms 7516 KB Output is correct
11 Correct 3 ms 7516 KB Output is correct
12 Correct 3 ms 7516 KB Output is correct
13 Correct 3 ms 7516 KB Output is correct
14 Correct 3 ms 7512 KB Output is correct
15 Correct 3 ms 7516 KB Output is correct
16 Correct 3 ms 7512 KB Output is correct
17 Correct 3 ms 7516 KB Output is correct
18 Correct 4 ms 7516 KB Output is correct
19 Correct 3 ms 7516 KB Output is correct
20 Correct 3 ms 7516 KB Output is correct
21 Correct 4 ms 7516 KB Output is correct
22 Correct 3 ms 7516 KB Output is correct
23 Correct 3 ms 7628 KB Output is correct
24 Correct 3 ms 7516 KB Output is correct
25 Correct 3 ms 7516 KB Output is correct
26 Correct 3 ms 7516 KB Output is correct
27 Correct 3 ms 7516 KB Output is correct
28 Correct 3 ms 7472 KB Output is correct
29 Correct 3 ms 7516 KB Output is correct
30 Correct 3 ms 7628 KB Output is correct
31 Correct 3 ms 7516 KB Output is correct
32 Correct 3 ms 7516 KB Output is correct
33 Correct 3 ms 7516 KB Output is correct
34 Correct 3 ms 7416 KB Output is correct
35 Correct 4 ms 7516 KB Output is correct
36 Correct 3 ms 7516 KB Output is correct
37 Correct 4 ms 7628 KB Output is correct
38 Correct 4 ms 7468 KB Output is correct
39 Correct 3 ms 7512 KB Output is correct
40 Correct 3 ms 7512 KB Output is correct
41 Correct 3 ms 7588 KB Output is correct
42 Correct 3 ms 7516 KB Output is correct
43 Correct 3 ms 7516 KB Output is correct
44 Correct 3 ms 7768 KB Output is correct
45 Correct 3 ms 7516 KB Output is correct
46 Correct 3 ms 7516 KB Output is correct
47 Correct 3 ms 7516 KB Output is correct
48 Correct 3 ms 7516 KB Output is correct
49 Correct 4 ms 7516 KB Output is correct
50 Correct 3 ms 7516 KB Output is correct
51 Correct 3 ms 7516 KB Output is correct
52 Correct 6 ms 8284 KB Output is correct
53 Correct 7 ms 8284 KB Output is correct
54 Correct 6 ms 8388 KB Output is correct
55 Correct 6 ms 8540 KB Output is correct
56 Correct 6 ms 8540 KB Output is correct
57 Correct 5 ms 8452 KB Output is correct
58 Correct 5 ms 8424 KB Output is correct
59 Correct 8 ms 8284 KB Output is correct
60 Correct 4 ms 8284 KB Output is correct
61 Correct 9 ms 8176 KB Output is correct
62 Correct 6 ms 8284 KB Output is correct
63 Correct 5 ms 8284 KB Output is correct
64 Correct 5 ms 8284 KB Output is correct
65 Correct 5 ms 8436 KB Output is correct
66 Correct 7 ms 8392 KB Output is correct
67 Correct 5 ms 8540 KB Output is correct
68 Correct 6 ms 8540 KB Output is correct
69 Correct 5 ms 8160 KB Output is correct
70 Correct 5 ms 8280 KB Output is correct
71 Correct 7 ms 8284 KB Output is correct
72 Correct 6 ms 8284 KB Output is correct
73 Correct 5 ms 8364 KB Output is correct
74 Correct 9 ms 8044 KB Output is correct
75 Correct 6 ms 8284 KB Output is correct
76 Correct 13 ms 8368 KB Output is correct
77 Correct 17 ms 8540 KB Output is correct
78 Execution timed out 2098 ms 8236 KB Time limit exceeded
79 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7516 KB Output is correct
2 Correct 3 ms 7516 KB Output is correct
3 Correct 4 ms 7428 KB Output is correct
4 Correct 3 ms 7516 KB Output is correct
5 Correct 3 ms 7516 KB Output is correct
6 Correct 3 ms 7584 KB Output is correct
7 Correct 4 ms 7516 KB Output is correct
8 Correct 3 ms 7516 KB Output is correct
9 Correct 3 ms 7588 KB Output is correct
10 Correct 3 ms 7516 KB Output is correct
11 Correct 3 ms 7516 KB Output is correct
12 Correct 3 ms 7516 KB Output is correct
13 Correct 3 ms 7516 KB Output is correct
14 Correct 3 ms 7512 KB Output is correct
15 Correct 3 ms 7516 KB Output is correct
16 Correct 3 ms 7512 KB Output is correct
17 Correct 3 ms 7516 KB Output is correct
18 Correct 4 ms 7516 KB Output is correct
19 Correct 3 ms 7516 KB Output is correct
20 Correct 3 ms 7516 KB Output is correct
21 Correct 4 ms 7516 KB Output is correct
22 Correct 3 ms 7516 KB Output is correct
23 Correct 3 ms 7628 KB Output is correct
24 Correct 3 ms 7516 KB Output is correct
25 Correct 3 ms 7516 KB Output is correct
26 Correct 3 ms 7516 KB Output is correct
27 Correct 3 ms 7516 KB Output is correct
28 Correct 3 ms 7472 KB Output is correct
29 Correct 3 ms 7516 KB Output is correct
30 Correct 3 ms 7628 KB Output is correct
31 Correct 3 ms 7516 KB Output is correct
32 Correct 3 ms 7516 KB Output is correct
33 Correct 3 ms 7516 KB Output is correct
34 Correct 3 ms 7416 KB Output is correct
35 Correct 4 ms 7516 KB Output is correct
36 Correct 3 ms 7516 KB Output is correct
37 Correct 4 ms 7628 KB Output is correct
38 Correct 4 ms 7468 KB Output is correct
39 Correct 3 ms 7512 KB Output is correct
40 Correct 3 ms 7512 KB Output is correct
41 Correct 3 ms 7588 KB Output is correct
42 Correct 3 ms 7516 KB Output is correct
43 Correct 3 ms 7516 KB Output is correct
44 Correct 3 ms 7768 KB Output is correct
45 Correct 3 ms 7516 KB Output is correct
46 Correct 3 ms 7516 KB Output is correct
47 Correct 3 ms 7516 KB Output is correct
48 Correct 3 ms 7516 KB Output is correct
49 Correct 4 ms 7516 KB Output is correct
50 Correct 3 ms 7516 KB Output is correct
51 Correct 3 ms 7516 KB Output is correct
52 Correct 4 ms 7512 KB Output is correct
53 Correct 8 ms 8852 KB Output is correct
54 Correct 53 ms 21504 KB Output is correct
55 Correct 55 ms 21372 KB Output is correct
56 Correct 58 ms 21280 KB Output is correct
57 Correct 54 ms 21508 KB Output is correct
58 Correct 90 ms 27904 KB Output is correct
59 Correct 66 ms 25584 KB Output is correct
60 Correct 62 ms 25604 KB Output is correct
61 Correct 53 ms 22272 KB Output is correct
62 Correct 45 ms 21820 KB Output is correct
63 Correct 64 ms 21248 KB Output is correct
64 Correct 64 ms 21248 KB Output is correct
65 Correct 52 ms 24628 KB Output is correct
66 Correct 74 ms 29184 KB Output is correct
67 Correct 69 ms 29952 KB Output is correct
68 Correct 64 ms 21168 KB Output is correct
69 Correct 76 ms 21252 KB Output is correct
70 Correct 67 ms 21248 KB Output is correct
71 Correct 43 ms 21568 KB Output is correct
72 Correct 45 ms 21712 KB Output is correct
73 Correct 55 ms 21540 KB Output is correct
74 Correct 6 ms 8284 KB Output is correct
75 Correct 7 ms 8284 KB Output is correct
76 Correct 6 ms 8388 KB Output is correct
77 Correct 6 ms 8540 KB Output is correct
78 Correct 6 ms 8540 KB Output is correct
79 Correct 5 ms 8452 KB Output is correct
80 Correct 5 ms 8424 KB Output is correct
81 Correct 8 ms 8284 KB Output is correct
82 Correct 4 ms 8284 KB Output is correct
83 Correct 9 ms 8176 KB Output is correct
84 Correct 6 ms 8284 KB Output is correct
85 Correct 5 ms 8284 KB Output is correct
86 Correct 5 ms 8284 KB Output is correct
87 Correct 5 ms 8436 KB Output is correct
88 Correct 7 ms 8392 KB Output is correct
89 Correct 5 ms 8540 KB Output is correct
90 Correct 6 ms 8540 KB Output is correct
91 Correct 5 ms 8160 KB Output is correct
92 Correct 5 ms 8280 KB Output is correct
93 Correct 7 ms 8284 KB Output is correct
94 Correct 6 ms 8284 KB Output is correct
95 Correct 5 ms 8364 KB Output is correct
96 Correct 9 ms 8044 KB Output is correct
97 Correct 6 ms 8284 KB Output is correct
98 Correct 13 ms 8368 KB Output is correct
99 Correct 17 ms 8540 KB Output is correct
100 Execution timed out 2098 ms 8236 KB Time limit exceeded
101 Halted 0 ms 0 KB -