Submission #744511

# Submission time Handle Problem Language Result Execution time Memory
744511 2023-05-18T16:03:04 Z Abito Duathlon (APIO18_duathlon) C++14
0 / 100
1000 ms 39088 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
using namespace std;
const int N=1e6+5;
int n,m,dpar[N],dsz[N],a,b,par[N];
vector<int> adj[N],q;
bool vis[N],dp[N],t[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;
}
void bfs(int source){
    q.clear();
    q.pb(source);
    par[source]=-1;
    for (int i=0;i<q.size();i++){
        int node=q[i];
        for (auto u:adj[node]){
            if (par[u] || u==b) continue;
            par[u]=node;
            q.pb(u);
        }
    }return;
}
int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    cin>>n>>m;
    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);
    }
    int ans=0;
    for (int i=1;i<=n;i++){
        for (int j=i+1;j<=n;j++){
            int x=getpar(i),y=getpar(j);
            if (x!=y) continue;
            a=i,b=j;
            memset(par,0,sizeof(par));
            memset(dp,0,sizeof(dp));
            bfs(a);
            for (int i=q.size()-1;i;i--){
                for (auto u:adj[q[i]]){
                    if (u==b) dp[q[i]]=true;
                }
                if (par[q[i]]>-1) dp[par[q[i]]]|=dp[q[i]];
            }
            int f=0;
            for (int i=1;i<=n;i++) {ans+=dp[i];f+=dp[i];}
            ans-=dp[a];
        }
    }ans*=2;
    cout<<ans<<endl;
    return 0;
}

Compilation message

count_triplets.cpp: In function 'void bfs(long long int)':
count_triplets.cpp:33: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]
   33 |     for (int i=0;i<q.size();i++){
      |                  ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 22 ms 32596 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 22 ms 32596 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1070 ms 38408 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1070 ms 32596 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1067 ms 39020 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1067 ms 32596 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1070 ms 39088 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 22 ms 32596 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 22 ms 32596 KB Output isn't correct
2 Halted 0 ms 0 KB -