Submission #744493

# Submission time Handle Problem Language Result Execution time Memory
744493 2023-05-18T15:47:46 Z Abito Duathlon (APIO18_duathlon) C++14
0 / 100
1000 ms 36772 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;
vector<int> adj[N];
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 dfs(int node){
    if (node==b) {dp[node]=true;return;}
    vis[node]=true;
    t[node]=true;
    for (auto u:adj[node]){
        if (!vis[u]) dfs(u);
        if (!t[u]) dp[node]|=dp[u];
    }t[node]=false;
    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(vis,0,sizeof(vis));
            memset(dp,0,sizeof(dp));
            dfs(a);
            for (int i=1;i<=n;i++) ans+=dp[i];
            ans-=2;
            //cout<<a<<' '<<b<<' '<<ans<<endl;
        }
    }ans*=2;
    cout<<ans<<endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 25672 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 25672 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1060 ms 36772 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1063 ms 25812 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1058 ms 31052 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1045 ms 25812 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1060 ms 31052 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 25672 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 25672 KB Output isn't correct
2 Halted 0 ms 0 KB -