Submission #744537

# Submission time Handle Problem Language Result Execution time Memory
744537 2023-05-18T17:28:28 Z Abito Duathlon (APIO18_duathlon) C++14
23 / 100
1000 ms 1048576 KB
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define endl '\n'
#define ep insert
#define pow pwr
#define sqrt sqrtt
#define elif else if
#define y1 YONE
#define int long long
#define ppb pop_back
using namespace std;
const int N=1e6+5;
int n,m,sz[N],par[N],dpar[N],dsz[N];
vector<int> adj[N],v;
set<pair<pair<int,int>,int>> s;
bool vis[N];
int getpar(int x){
    if (x==dpar[x]) return x;
    return dpar[x]=getpar(dpar[x]);
}
void link(int x,int y){
    x=getpar(x);y=getpar(y);
    if (x==y) return;
    if (dsz[x]>dsz[y]) swap(x,y);
    dpar[x]=y;
    dsz[y]+=dsz[x];
    return;
}
int getsize(int node,int p){
    par[node]=p;
    sz[node]=1;
    for (auto u:adj[node]){
        if (u==p) continue;
        sz[node]+=getsize(u,node);
    }return sz[node];
}
void backtrack(int node){
    v.pb(node);
    for (int i=0;i<v.size();i++){
        for (int j=i+1;j<v.size();j++){
            for (int k=j+1;k<v.size();k++) s.ep({{v[i],v[j]},v[k]});
        }
    }
    vis[node]=true;
    for (auto u:adj[node]){
        if (vis[u]) continue;
        backtrack(u);
    }
    v.ppb();
    vis[node]=false;
    return;
}
int32_t main(){
    //ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    cin>>n>>m;
    if (n<=10){
        for (int i=1;i<=m;i++){
            int x,y;
            cin>>x>>y;
            adj[x].pb(y);
            adj[y].pb(x);
        }
        for (int i=1;i<=n;i++) backtrack(i);
        cout<<s.size()<<endl;
        //for (auto u:s) cout<<u.F.F<<' '<<u.F.S<<' '<<u.S<<endl;
        return 0;
    }
    for (int i=1;i<=n;i++){
        dsz[i]=1;
        dpar[i]=i;
    }
    for (int i=1;i<=m;i++){
        int x,y;
        cin>>x>>y;
        adj[x].pb(y);
        adj[y].pb(x);
        link(x,y);
    }
    for (int i=1;i<=n;i++){
        if (sz[i]) continue;
        getsize(i,0);
    }
    int ans=0;
    for (int i=1;i<=n;i++){
        int x=sz[i]-1;
        for (auto u:adj[i]){
            if (u==par[i]) continue;
            x-=sz[u];
            ans+=x*sz[u];
        }ans+=(dsz[getpar(i)]-sz[i])*(sz[i]-1);
    }
    cout<<ans*2LL<<endl;
    return 0;
}

Compilation message

count_triplets.cpp: In function 'void backtrack(long long int)':
count_triplets.cpp:41:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |     for (int i=0;i<v.size();i++){
      |                  ~^~~~~~~~~
count_triplets.cpp:42:25: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |         for (int j=i+1;j<v.size();j++){
      |                        ~^~~~~~~~~
count_triplets.cpp:43:29: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |             for (int k=j+1;k<v.size();k++) s.ep({{v[i],v[j]},v[k]});
      |                            ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23800 KB Output is correct
2 Correct 13 ms 23764 KB Output is correct
3 Correct 15 ms 23796 KB Output is correct
4 Correct 15 ms 23672 KB Output is correct
5 Correct 13 ms 23792 KB Output is correct
6 Correct 13 ms 23800 KB Output is correct
7 Correct 13 ms 23796 KB Output is correct
8 Correct 31 ms 23764 KB Output is correct
9 Execution timed out 1081 ms 23940 KB Time limit exceeded
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23800 KB Output is correct
2 Correct 13 ms 23764 KB Output is correct
3 Correct 15 ms 23796 KB Output is correct
4 Correct 15 ms 23672 KB Output is correct
5 Correct 13 ms 23792 KB Output is correct
6 Correct 13 ms 23800 KB Output is correct
7 Correct 13 ms 23796 KB Output is correct
8 Correct 31 ms 23764 KB Output is correct
9 Execution timed out 1081 ms 23940 KB Time limit exceeded
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1070 ms 350628 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23892 KB Output is correct
2 Correct 15 ms 23800 KB Output is correct
3 Correct 12 ms 23844 KB Output is correct
4 Correct 12 ms 23840 KB Output is correct
5 Correct 13 ms 23924 KB Output is correct
6 Correct 13 ms 23900 KB Output is correct
7 Correct 13 ms 23800 KB Output is correct
8 Correct 14 ms 23800 KB Output is correct
9 Correct 16 ms 23892 KB Output is correct
10 Correct 13 ms 23892 KB Output is correct
11 Correct 13 ms 23892 KB Output is correct
12 Correct 13 ms 23836 KB Output is correct
13 Correct 14 ms 23800 KB Output is correct
14 Correct 14 ms 23852 KB Output is correct
15 Correct 14 ms 23804 KB Output is correct
16 Correct 13 ms 23868 KB Output is correct
17 Correct 13 ms 23892 KB Output is correct
18 Correct 13 ms 23848 KB Output is correct
19 Correct 13 ms 23840 KB Output is correct
20 Correct 13 ms 23888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 111 ms 30616 KB Output is correct
2 Correct 113 ms 31684 KB Output is correct
3 Correct 126 ms 31752 KB Output is correct
4 Correct 102 ms 31584 KB Output is correct
5 Correct 109 ms 31688 KB Output is correct
6 Correct 115 ms 33524 KB Output is correct
7 Correct 126 ms 33296 KB Output is correct
8 Correct 108 ms 32776 KB Output is correct
9 Correct 106 ms 32388 KB Output is correct
10 Correct 117 ms 31692 KB Output is correct
11 Correct 108 ms 31436 KB Output is correct
12 Correct 117 ms 31372 KB Output is correct
13 Correct 104 ms 31436 KB Output is correct
14 Correct 111 ms 31144 KB Output is correct
15 Correct 87 ms 30884 KB Output is correct
16 Correct 63 ms 29960 KB Output is correct
17 Correct 90 ms 31552 KB Output is correct
18 Correct 83 ms 31532 KB Output is correct
19 Correct 87 ms 31620 KB Output is correct
20 Correct 93 ms 31664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23764 KB Output is correct
2 Correct 13 ms 23892 KB Output is correct
3 Runtime error 638 ms 1048576 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 126 ms 31180 KB Output is correct
2 Correct 145 ms 31780 KB Output is correct
3 Runtime error 904 ms 1048576 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23800 KB Output is correct
2 Correct 13 ms 23764 KB Output is correct
3 Correct 15 ms 23796 KB Output is correct
4 Correct 15 ms 23672 KB Output is correct
5 Correct 13 ms 23792 KB Output is correct
6 Correct 13 ms 23800 KB Output is correct
7 Correct 13 ms 23796 KB Output is correct
8 Correct 31 ms 23764 KB Output is correct
9 Execution timed out 1081 ms 23940 KB Time limit exceeded
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23800 KB Output is correct
2 Correct 13 ms 23764 KB Output is correct
3 Correct 15 ms 23796 KB Output is correct
4 Correct 15 ms 23672 KB Output is correct
5 Correct 13 ms 23792 KB Output is correct
6 Correct 13 ms 23800 KB Output is correct
7 Correct 13 ms 23796 KB Output is correct
8 Correct 31 ms 23764 KB Output is correct
9 Execution timed out 1081 ms 23940 KB Time limit exceeded
10 Halted 0 ms 0 KB -