Submission #60004

# Submission time Handle Problem Language Result Execution time Memory
60004 2018-07-23T12:03:39 Z Flugan42 Duathlon (APIO18_duathlon) C++14
36 / 100
1000 ms 12532 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef pair<ll,ll> ii;
typedef vector<ii> vii;
#define rep(i,a,b) for(int i = a; i < b; i++)
#define per(i,a,b) for(int i = a; i >= b; i--)
#define inf 1000000000000000000
#define sz(x) (ll)(x).size()

ll n,m,u,v,cur;
vector<vi> edges;
vi _,vis,tree,vis2,cnt,path;
vector<vector<vi> > dp;

void dfs(ll a){
  tree.push_back(a);
  rep(i,0,sz(edges[a])){
    ll b = edges[a][i];
    if (vis[b] == 0) {
      vis[b] = cur;
      dfs(b);
    }
  }
}

ll dfs2(ll a){
  vis2[a] = 1;
  if (cnt[a] != -1) return cnt[a];
  ll ans = 1;
  rep(i,0,sz(edges[a])){
    ll b = edges[a][i];
    if (vis2[b] == 0) {
      ans += dfs2(b);
    }
  }
  return cnt[a] = ans;
}

ll center(ll a){
  ll ans = 0,big = 0;
  rep(i,0,sz(edges[a])){
    ll b = edges[a][i];
    if (cnt[b] > cnt[a]) { continue; }
    ans += (sz(tree)-1-cnt[b])*cnt[b];
    big += cnt[b];
  }
  ans += big*(sz(tree)-1-big);
  return ans;
}

void dfs3(ll a){
  path.push_back(a);
  rep(i,1,sz(path)-1) dp[path[0]][path[i]][a] = 1;
  rep(i,0,sz(edges[a])){
    ll b = edges[a][i];
    if (!vis[b]){
      vis[b] = 1;
      dfs3(b);
    }
  }
  path.pop_back();
  vis[a] = 0;
}

int main(){
  cin >> n >> m;
  edges.assign(n,_);
  rep(i,0,m){
    cin >> u >> v; u--; v--;
    edges[u].push_back(v);
    edges[v].push_back(u);
  }
  bool check = true;
  rep(i,0,n) if (sz(edges[i])>2) check = false;
  vis.assign(n,0); vis2.assign(n,0); cnt.assign(n,-1);
  cur = 1; ll res = 0;
  if (n <= 50){
    vector<vi> __;
    _.assign(n,0);
    __.assign(n,_);
    dp.assign(n,__);
    rep(i,0,n){
      vis.assign(n,0);
      vis[i] = 1;
      dfs3(i);
    }
    rep(i,0,n) rep(j,0,n) rep(k,0,n) if (dp[i][j][k]) res++;
    cout << res << endl;
    exit(0);
  }
  if (check){
    rep(i,0,n){
      if (vis[i] != 0) continue;
      tree.clear();
      vis[i] = cur; dfs(i); cur++;
      bool cyc = true; ll A = sz(tree);
      rep(j,0,A) if (sz(edges[tree[j]]) < 2) cyc = false;
      if (cyc) res += A*(A-1)*(A-2);
      else res += A*(A-1)*(A-2)/3;
    }
    cout << res << endl;
    exit(0);
  }
  rep(i,0,n){
    if (vis[i] != 0) continue;
    tree.clear();
    vis[i] = cur; dfs(i); cur++;
    dfs2(tree[0]);
    rep(j,0,sz(tree)){ res += center(tree[j]);  }
  }
  cout << res << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 2 ms 560 KB Output is correct
4 Correct 2 ms 560 KB Output is correct
5 Correct 3 ms 560 KB Output is correct
6 Correct 3 ms 592 KB Output is correct
7 Correct 3 ms 596 KB Output is correct
8 Correct 3 ms 620 KB Output is correct
9 Correct 21 ms 620 KB Output is correct
10 Correct 538 ms 620 KB Output is correct
11 Correct 2 ms 620 KB Output is correct
12 Correct 0 ms 620 KB Output is correct
13 Correct 3 ms 620 KB Output is correct
14 Correct 3 ms 620 KB Output is correct
15 Correct 2 ms 620 KB Output is correct
16 Correct 2 ms 620 KB Output is correct
17 Correct 3 ms 620 KB Output is correct
18 Correct 2 ms 620 KB Output is correct
19 Correct 3 ms 620 KB Output is correct
20 Correct 3 ms 620 KB Output is correct
21 Correct 3 ms 620 KB Output is correct
22 Correct 3 ms 620 KB Output is correct
23 Correct 3 ms 620 KB Output is correct
24 Correct 2 ms 620 KB Output is correct
25 Correct 3 ms 620 KB Output is correct
26 Correct 2 ms 620 KB Output is correct
27 Correct 3 ms 620 KB Output is correct
28 Correct 3 ms 620 KB Output is correct
29 Correct 2 ms 620 KB Output is correct
30 Correct 3 ms 620 KB Output is correct
31 Correct 0 ms 620 KB Output is correct
32 Correct 3 ms 620 KB Output is correct
33 Correct 3 ms 620 KB Output is correct
34 Correct 2 ms 620 KB Output is correct
35 Correct 3 ms 620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 2 ms 560 KB Output is correct
4 Correct 2 ms 560 KB Output is correct
5 Correct 3 ms 560 KB Output is correct
6 Correct 3 ms 592 KB Output is correct
7 Correct 3 ms 596 KB Output is correct
8 Correct 3 ms 620 KB Output is correct
9 Correct 21 ms 620 KB Output is correct
10 Correct 538 ms 620 KB Output is correct
11 Correct 2 ms 620 KB Output is correct
12 Correct 0 ms 620 KB Output is correct
13 Correct 3 ms 620 KB Output is correct
14 Correct 3 ms 620 KB Output is correct
15 Correct 2 ms 620 KB Output is correct
16 Correct 2 ms 620 KB Output is correct
17 Correct 3 ms 620 KB Output is correct
18 Correct 2 ms 620 KB Output is correct
19 Correct 3 ms 620 KB Output is correct
20 Correct 3 ms 620 KB Output is correct
21 Correct 3 ms 620 KB Output is correct
22 Correct 3 ms 620 KB Output is correct
23 Correct 3 ms 620 KB Output is correct
24 Correct 2 ms 620 KB Output is correct
25 Correct 3 ms 620 KB Output is correct
26 Correct 2 ms 620 KB Output is correct
27 Correct 3 ms 620 KB Output is correct
28 Correct 3 ms 620 KB Output is correct
29 Correct 2 ms 620 KB Output is correct
30 Correct 3 ms 620 KB Output is correct
31 Correct 0 ms 620 KB Output is correct
32 Correct 3 ms 620 KB Output is correct
33 Correct 3 ms 620 KB Output is correct
34 Correct 2 ms 620 KB Output is correct
35 Correct 3 ms 620 KB Output is correct
36 Correct 4 ms 1644 KB Output is correct
37 Correct 4 ms 1644 KB Output is correct
38 Correct 10 ms 1644 KB Output is correct
39 Execution timed out 1032 ms 1676 KB Time limit exceeded
40 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 237 ms 12532 KB Output is correct
2 Correct 219 ms 12532 KB Output is correct
3 Correct 260 ms 12532 KB Output is correct
4 Correct 197 ms 12532 KB Output is correct
5 Correct 221 ms 12532 KB Output is correct
6 Correct 189 ms 12532 KB Output is correct
7 Correct 212 ms 12532 KB Output is correct
8 Correct 185 ms 12532 KB Output is correct
9 Correct 198 ms 12532 KB Output is correct
10 Correct 201 ms 12532 KB Output is correct
11 Correct 175 ms 12532 KB Output is correct
12 Correct 184 ms 12532 KB Output is correct
13 Correct 172 ms 12532 KB Output is correct
14 Correct 155 ms 12532 KB Output is correct
15 Correct 101 ms 12532 KB Output is correct
16 Correct 137 ms 12532 KB Output is correct
17 Correct 13 ms 12532 KB Output is correct
18 Correct 11 ms 12532 KB Output is correct
19 Correct 12 ms 12532 KB Output is correct
20 Correct 10 ms 12532 KB Output is correct
21 Correct 9 ms 12532 KB Output is correct
22 Correct 10 ms 12532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 12532 KB Output is correct
2 Correct 5 ms 12532 KB Output is correct
3 Correct 3 ms 12532 KB Output is correct
4 Correct 3 ms 12532 KB Output is correct
5 Correct 3 ms 12532 KB Output is correct
6 Correct 3 ms 12532 KB Output is correct
7 Correct 3 ms 12532 KB Output is correct
8 Correct 5 ms 12532 KB Output is correct
9 Correct 4 ms 12532 KB Output is correct
10 Correct 4 ms 12532 KB Output is correct
11 Correct 4 ms 12532 KB Output is correct
12 Correct 4 ms 12532 KB Output is correct
13 Correct 4 ms 12532 KB Output is correct
14 Correct 4 ms 12532 KB Output is correct
15 Correct 3 ms 12532 KB Output is correct
16 Correct 4 ms 12532 KB Output is correct
17 Correct 2 ms 12532 KB Output is correct
18 Correct 3 ms 12532 KB Output is correct
19 Correct 3 ms 12532 KB Output is correct
20 Correct 3 ms 12532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 217 ms 12532 KB Output is correct
2 Correct 217 ms 12532 KB Output is correct
3 Correct 272 ms 12532 KB Output is correct
4 Correct 216 ms 12532 KB Output is correct
5 Correct 254 ms 12532 KB Output is correct
6 Correct 196 ms 12532 KB Output is correct
7 Correct 236 ms 12532 KB Output is correct
8 Correct 226 ms 12532 KB Output is correct
9 Correct 243 ms 12532 KB Output is correct
10 Correct 221 ms 12532 KB Output is correct
11 Correct 220 ms 12532 KB Output is correct
12 Correct 215 ms 12532 KB Output is correct
13 Correct 285 ms 12532 KB Output is correct
14 Correct 197 ms 12532 KB Output is correct
15 Correct 146 ms 12532 KB Output is correct
16 Correct 93 ms 12532 KB Output is correct
17 Correct 151 ms 12532 KB Output is correct
18 Correct 170 ms 12532 KB Output is correct
19 Correct 188 ms 12532 KB Output is correct
20 Correct 235 ms 12532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 12532 KB Output is correct
2 Correct 3 ms 12532 KB Output is correct
3 Incorrect 4 ms 12532 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 261 ms 12532 KB Output is correct
2 Correct 276 ms 12532 KB Output is correct
3 Incorrect 245 ms 12532 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 2 ms 560 KB Output is correct
4 Correct 2 ms 560 KB Output is correct
5 Correct 3 ms 560 KB Output is correct
6 Correct 3 ms 592 KB Output is correct
7 Correct 3 ms 596 KB Output is correct
8 Correct 3 ms 620 KB Output is correct
9 Correct 21 ms 620 KB Output is correct
10 Correct 538 ms 620 KB Output is correct
11 Correct 2 ms 620 KB Output is correct
12 Correct 0 ms 620 KB Output is correct
13 Correct 3 ms 620 KB Output is correct
14 Correct 3 ms 620 KB Output is correct
15 Correct 2 ms 620 KB Output is correct
16 Correct 2 ms 620 KB Output is correct
17 Correct 3 ms 620 KB Output is correct
18 Correct 2 ms 620 KB Output is correct
19 Correct 3 ms 620 KB Output is correct
20 Correct 3 ms 620 KB Output is correct
21 Correct 3 ms 620 KB Output is correct
22 Correct 3 ms 620 KB Output is correct
23 Correct 3 ms 620 KB Output is correct
24 Correct 2 ms 620 KB Output is correct
25 Correct 3 ms 620 KB Output is correct
26 Correct 2 ms 620 KB Output is correct
27 Correct 3 ms 620 KB Output is correct
28 Correct 3 ms 620 KB Output is correct
29 Correct 2 ms 620 KB Output is correct
30 Correct 3 ms 620 KB Output is correct
31 Correct 0 ms 620 KB Output is correct
32 Correct 3 ms 620 KB Output is correct
33 Correct 3 ms 620 KB Output is correct
34 Correct 2 ms 620 KB Output is correct
35 Correct 3 ms 620 KB Output is correct
36 Correct 4 ms 1644 KB Output is correct
37 Correct 4 ms 1644 KB Output is correct
38 Correct 10 ms 1644 KB Output is correct
39 Execution timed out 1032 ms 1676 KB Time limit exceeded
40 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 2 ms 560 KB Output is correct
4 Correct 2 ms 560 KB Output is correct
5 Correct 3 ms 560 KB Output is correct
6 Correct 3 ms 592 KB Output is correct
7 Correct 3 ms 596 KB Output is correct
8 Correct 3 ms 620 KB Output is correct
9 Correct 21 ms 620 KB Output is correct
10 Correct 538 ms 620 KB Output is correct
11 Correct 2 ms 620 KB Output is correct
12 Correct 0 ms 620 KB Output is correct
13 Correct 3 ms 620 KB Output is correct
14 Correct 3 ms 620 KB Output is correct
15 Correct 2 ms 620 KB Output is correct
16 Correct 2 ms 620 KB Output is correct
17 Correct 3 ms 620 KB Output is correct
18 Correct 2 ms 620 KB Output is correct
19 Correct 3 ms 620 KB Output is correct
20 Correct 3 ms 620 KB Output is correct
21 Correct 3 ms 620 KB Output is correct
22 Correct 3 ms 620 KB Output is correct
23 Correct 3 ms 620 KB Output is correct
24 Correct 2 ms 620 KB Output is correct
25 Correct 3 ms 620 KB Output is correct
26 Correct 2 ms 620 KB Output is correct
27 Correct 3 ms 620 KB Output is correct
28 Correct 3 ms 620 KB Output is correct
29 Correct 2 ms 620 KB Output is correct
30 Correct 3 ms 620 KB Output is correct
31 Correct 0 ms 620 KB Output is correct
32 Correct 3 ms 620 KB Output is correct
33 Correct 3 ms 620 KB Output is correct
34 Correct 2 ms 620 KB Output is correct
35 Correct 3 ms 620 KB Output is correct
36 Correct 4 ms 1644 KB Output is correct
37 Correct 4 ms 1644 KB Output is correct
38 Correct 10 ms 1644 KB Output is correct
39 Execution timed out 1032 ms 1676 KB Time limit exceeded
40 Halted 0 ms 0 KB -