답안 #990611

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
990611 2024-05-30T17:17:40 Z grogu 철인 이종 경기 (APIO18_duathlon) C++14
31 / 100
46 ms 30544 KB
    // __builtin_popcount(x)
    // __builtin_popcountll(x)
    #define here cerr<<"===========================================\n"
    #include <bits/stdc++.h>
    #define ld double
    #define ll long long
    #define ull unsigned long long
    #define llinf 100000000000000000LL // 10^17
    #define iinf 2000000000 // 2*10^9
    #define pb push_back
    #define popb pop_back
    #define fi first
    #define sc second
    #define endl '\n'
    #define pii pair<int,int>
    #define pll pair<ll,ll>
    #define pld pair<ld,ld>
    #define sz(a) int(a.size())
    #define all(a) a.begin(),a.end()
    #define ceri(a,l,r) {for(ll i_ = l;i_<=r;i_++) cerr<<a[i_]<< " ";cerr<<endl;}
    using namespace std;
     
    #define maxn 200005
    ll n,m;
    vector<ll> g[maxn];
    vector<ll> v[maxn];
    ll low[maxn];
    ll in[maxn];
    bool vis[maxn];
    ll siz[maxn];
    ll it = 1;
    ll cnt = 1;
    ll comp = 0;
    stack<ll> st;
    void dfs(ll u,ll par){
        comp++;
        in[u] = it++;
        low[u] = in[u];
        st.push(u);
        for(ll s : g[u]){
            if(s==par) continue;
            if(in[s]){
                low[u] = min(low[u],low[s]);
            }else{
                dfs(s,u);
                low[u] = min(low[u],low[s]);
                if(low[s]>in[u]){
                    v[u].pb(n+cnt);
                    while(sz(st)){
                        ll to = st.top();
                        st.pop();
                        v[n+cnt].pb(to);
                        if(to==s) break;
                    }
                    cnt++;
                }
            }
        }
     
    }
    ll ans = 0;
    ll f3(ll x){
        return x*(x-1)*(x-2);
    }
    ll f2(ll x){
        return x*(x-1);
    }
    void dfs2(ll u){
        if(u<=n) siz[u] = 1;
        for(ll s : v[u]){
            dfs2(s);
            siz[u]+=siz[s];
            if(u>n) ans-=f2(siz[s])*sz(v[u]);
        }
        if(u>n) ans-=f2(comp-siz[u])*sz(v[u]);
    }
    int main(){
    	ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0);
        cin >> n >> m;
        for(ll i = 1;i<=m;i++){
            ll x,y; cin >> x >> y;
            g[x].pb(y);
            g[y].pb(x);
        }
        for(ll i = 1;i<=n;i++){
            if(in[i]==0){
                comp = 0;
                dfs(i,i);
                ans+=f3(comp);
                dfs2(i);
            }
        }
        cout<<ans<<endl;
    	return 0;
    }
    /*
    4 3
    1 2
    2 3
    3 4
    out: 8
    */
    /*
    4 4
    1 2
    2 3
    3 4
    4 2
    out: 14
    */
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12380 KB Output is correct
2 Correct 2 ms 12376 KB Output is correct
3 Correct 2 ms 12380 KB Output is correct
4 Correct 2 ms 12376 KB Output is correct
5 Correct 2 ms 12380 KB Output is correct
6 Correct 2 ms 12380 KB Output is correct
7 Incorrect 2 ms 12380 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12380 KB Output is correct
2 Correct 2 ms 12376 KB Output is correct
3 Correct 2 ms 12380 KB Output is correct
4 Correct 2 ms 12376 KB Output is correct
5 Correct 2 ms 12380 KB Output is correct
6 Correct 2 ms 12380 KB Output is correct
7 Incorrect 2 ms 12380 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 26308 KB Output is correct
2 Correct 30 ms 26204 KB Output is correct
3 Correct 40 ms 25936 KB Output is correct
4 Correct 34 ms 26192 KB Output is correct
5 Correct 37 ms 22868 KB Output is correct
6 Correct 40 ms 25172 KB Output is correct
7 Correct 39 ms 23636 KB Output is correct
8 Correct 39 ms 24136 KB Output is correct
9 Correct 39 ms 22580 KB Output is correct
10 Correct 37 ms 22612 KB Output is correct
11 Correct 27 ms 19796 KB Output is correct
12 Correct 27 ms 19884 KB Output is correct
13 Correct 29 ms 19804 KB Output is correct
14 Correct 26 ms 19548 KB Output is correct
15 Correct 23 ms 19032 KB Output is correct
16 Correct 22 ms 18780 KB Output is correct
17 Correct 4 ms 14428 KB Output is correct
18 Correct 4 ms 14428 KB Output is correct
19 Correct 4 ms 14560 KB Output is correct
20 Correct 4 ms 14428 KB Output is correct
21 Correct 4 ms 14428 KB Output is correct
22 Correct 4 ms 14428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 12632 KB Output is correct
2 Correct 3 ms 12380 KB Output is correct
3 Correct 4 ms 12600 KB Output is correct
4 Correct 3 ms 12636 KB Output is correct
5 Correct 3 ms 12636 KB Output is correct
6 Correct 3 ms 12632 KB Output is correct
7 Correct 3 ms 12632 KB Output is correct
8 Correct 3 ms 12636 KB Output is correct
9 Correct 2 ms 12636 KB Output is correct
10 Correct 3 ms 12636 KB Output is correct
11 Correct 2 ms 12636 KB Output is correct
12 Correct 2 ms 12636 KB Output is correct
13 Correct 2 ms 12636 KB Output is correct
14 Correct 2 ms 12380 KB Output is correct
15 Correct 2 ms 12380 KB Output is correct
16 Correct 3 ms 12380 KB Output is correct
17 Correct 2 ms 12380 KB Output is correct
18 Correct 2 ms 12380 KB Output is correct
19 Correct 3 ms 12564 KB Output is correct
20 Correct 2 ms 12636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 23124 KB Output is correct
2 Correct 39 ms 23120 KB Output is correct
3 Correct 42 ms 23124 KB Output is correct
4 Correct 40 ms 23132 KB Output is correct
5 Correct 39 ms 23188 KB Output is correct
6 Correct 46 ms 30544 KB Output is correct
7 Correct 46 ms 27988 KB Output is correct
8 Correct 44 ms 26704 KB Output is correct
9 Correct 42 ms 25680 KB Output is correct
10 Correct 36 ms 23120 KB Output is correct
11 Correct 40 ms 23120 KB Output is correct
12 Correct 37 ms 23120 KB Output is correct
13 Correct 36 ms 23124 KB Output is correct
14 Correct 32 ms 22608 KB Output is correct
15 Correct 32 ms 21844 KB Output is correct
16 Correct 20 ms 19800 KB Output is correct
17 Correct 28 ms 22224 KB Output is correct
18 Correct 25 ms 22344 KB Output is correct
19 Correct 26 ms 22724 KB Output is correct
20 Correct 26 ms 22252 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12636 KB Output is correct
2 Correct 2 ms 12380 KB Output is correct
3 Incorrect 3 ms 12380 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 23124 KB Output is correct
2 Correct 40 ms 23376 KB Output is correct
3 Incorrect 40 ms 21848 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12380 KB Output is correct
2 Correct 2 ms 12376 KB Output is correct
3 Correct 2 ms 12380 KB Output is correct
4 Correct 2 ms 12376 KB Output is correct
5 Correct 2 ms 12380 KB Output is correct
6 Correct 2 ms 12380 KB Output is correct
7 Incorrect 2 ms 12380 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12380 KB Output is correct
2 Correct 2 ms 12376 KB Output is correct
3 Correct 2 ms 12380 KB Output is correct
4 Correct 2 ms 12376 KB Output is correct
5 Correct 2 ms 12380 KB Output is correct
6 Correct 2 ms 12380 KB Output is correct
7 Incorrect 2 ms 12380 KB Output isn't correct
8 Halted 0 ms 0 KB -