답안 #912738

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
912738 2024-01-19T19:13:33 Z imarn 철인 이종 경기 (APIO18_duathlon) C++14
0 / 100
1000 ms 1048576 KB
#include<bits/stdc++.h>
#define f first
#define s second
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define sz(x) (int)x.size()
#define all(x) x.begin(),x.end()
#define vi vector<int>
#define vvi vector<vi>
using namespace std;
const int N=1e5+5;
vi g[N];stack<int>st;
vvi cmp,bst;
unsigned ll d[N]{0},lo[N]{0},t=0,ap[N]{0},id[N]{0},cur=0,isap[N]{0},sz[N],dp[N];
void dfs(int u,int p){
    lo[u]=d[u]=++t;st.push(u);
    for(auto v:g[u]){
        if(!d[v]){
            dfs(v,u);
            lo[u]=min(lo[u],lo[v]);
            if(d[u]<=lo[v]){
                ap[u] = (d[u]>1||d[v]>2);cmp.pb({u});
                while(cmp.back().back()!=v){
                    cmp.back().pb(st.top());st.pop();
                }
            }
        }
        else if(v!=p)lo[u]=min(lo[u],d[v]);
    }
}
void build(int n){
    for(int i=1;i<=n;i++)if(ap[i])id[i]=cur++,isap[id[i]]=1,bst.pb({}),sz[id[i]]=1;
    for(auto it : cmp){
        bst.pb({});sz[cur]=it.size();
        for(auto ij : it){
            if(!ap[ij])id[ij]=cur;
            else {
                bst[cur].pb(id[ij]);
                bst[id[ij]].pb(cur);
            }
        }cur++;
    }
}ll ans=0,n;
void solve(int u,int p){
    dp[u]=1;
    ll tt=0;
    for(auto v:g[u]){
        if(v==p)continue;
        solve(v,u);
        if(isap[u])ans+=2*(dp[u]-1)*(dp[v]);
        dp[u]+=dp[v];
    }
    if(isap[u])ans+=2*(n-dp[u])*(dp[u]-1);
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    int m;cin>>n>>m;
    for(int i=1;i<=m;i++){
        int u,v;cin>>u>>v;
        g[u].pb(v);g[v].pb(u);
    }
    //dfs(1,1);build(n);
    for(int i=1;i<=n;i++)sz[i]=1,isap[i]=1;
    solve(1,1);cout<<ans;
}

Compilation message

count_triplets.cpp: In function 'void solve(int, int)':
count_triplets.cpp:48:8: warning: unused variable 'tt' [-Wunused-variable]
   48 |     ll tt=0;
      |        ^~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 647 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 647 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1094 ms 932404 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5980 KB Output is correct
2 Correct 2 ms 5988 KB Output is correct
3 Correct 2 ms 5980 KB Output is correct
4 Correct 2 ms 5980 KB Output is correct
5 Correct 2 ms 5980 KB Output is correct
6 Correct 2 ms 5980 KB Output is correct
7 Correct 2 ms 5980 KB Output is correct
8 Correct 2 ms 5980 KB Output is correct
9 Correct 2 ms 5980 KB Output is correct
10 Incorrect 3 ms 6088 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 11356 KB Output is correct
2 Correct 26 ms 11344 KB Output is correct
3 Correct 27 ms 11552 KB Output is correct
4 Correct 30 ms 11356 KB Output is correct
5 Correct 29 ms 11352 KB Output is correct
6 Correct 31 ms 15444 KB Output is correct
7 Correct 29 ms 14164 KB Output is correct
8 Correct 31 ms 13440 KB Output is correct
9 Correct 29 ms 12636 KB Output is correct
10 Incorrect 28 ms 11352 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5980 KB Output is correct
2 Correct 2 ms 5980 KB Output is correct
3 Runtime error 725 ms 1048576 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 11356 KB Output is correct
2 Correct 27 ms 11356 KB Output is correct
3 Runtime error 817 ms 1048576 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 647 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 647 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -