답안 #233852

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
233852 2020-05-22T01:54:49 Z gs18115 철인 이종 경기 (APIO18_duathlon) C++14
10 / 100
719 ms 1048576 KB
#include<iostream>
#include<vector>
#include<algorithm>
#define ep emplace
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int>pi;
typedef pair<ll,ll>pl;
const int inf=1e9+7;
const ll INF=1e18+7;
vector<int>adj[100010];
vector<vector<pi> >bcc;
vector<pi>stk;
vector<int>cur;
int disc[100010];
int dct;
bool arp[100010];
int dfs(int x,int p)
{
    cur.eb(x);
    int ret=disc[x]=++dct;
    int c=0;
    for(int&t:adj[x])
    {
        if(disc[t]!=0)
        {
            ret=min(ret,disc[t]);
            if(disc[x]>disc[t])
                stk.eb(t,x);
        }
        else
        {
            int rt=dfs(t,x);
            if(rt>=disc[x])
            {
                vector<pi>cb;
                pi b(-1,-1);
                while(b!=pi(x,t))
                {
                    b=stk.back();
                    stk.pop_back();
                    cb.eb(b);
                }
                bcc.eb(cb);
                c++;
            }
            ret=min(ret,rt);
        }
    }
    if(c-(p==0?1:0)>0)
        arp[x]=1;
    return ret;
}
vector<int>adj2[200010];
int sz[100010],siz[100010];
int pa[100010];
void dfs2(int x,int p)
{
    pa[x]=p;
    sz[x]=siz[x];
    for(int&t:adj2[x])
        if(t!=p)
            dfs2(t,x),sz[x]+=sz[t];
    return;
}
int num[100010];
inline ll npr(int n,int r)
{
    ll ret=1;
    for(int i=n;i>n-r;i--)
        ret*=i;
    return ret;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        int u,v;
        cin>>u>>v;
        adj[u].eb(v);
        adj[v].eb(u);
    }
    ll ans=0;
    for(int v=0;v++<n;)
    {
        if(disc[v]==0)
        {
            cur.clear();
            bcc.clear();
            bcc.eb(vector<pi>());
            dfs(v,0);
            int bct=(int)bcc.size()-1,vct=bct;
            if(bct==0)
                continue;
            for(int&t:cur)
                if(arp[t])
                    num[t]=++vct;
            for(int i=0;i++<vct;)
                adj2[i].clear(),siz[i]=1;
            for(int i=0;i++<bct;)
            {
                vector<int>curv;
                for(pi&t:bcc[i])
                    curv.eb(t.fi),curv.eb(t.se);
                sort(all(curv));
                curv.erase(unique(all(curv)),curv.end());
                siz[i]=(int)curv.size();
                for(int&t:curv)
                    if(arp[t])
                        adj2[i].eb(num[t]),adj2[num[t]].eb(i),siz[i]--;
            }
            dfs2(1,0);
            ll cans=0;
            for(int i=0;i++<bct;)
            {
                int nsz=siz[i]+(int)adj2[i].size()-1;
                for(int&t:adj2[i])
                    if(t!=pa[i])
                        cans+=nsz*npr(sz[t],2);
                if(pa[i]!=0)
                    cans+=nsz*npr(sz[1]-sz[i],2);
            }
            ans+=npr(sz[1],3)-cans;
        }
    }
    cout<<ans<<endl;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 7424 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 7424 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 118 ms 30120 KB Output is correct
2 Correct 103 ms 30056 KB Output is correct
3 Runtime error 138 ms 53792 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 7552 KB Output is correct
2 Correct 10 ms 7552 KB Output is correct
3 Correct 10 ms 7552 KB Output is correct
4 Correct 9 ms 7680 KB Output is correct
5 Correct 9 ms 7680 KB Output is correct
6 Correct 10 ms 7680 KB Output is correct
7 Correct 9 ms 7680 KB Output is correct
8 Correct 9 ms 7680 KB Output is correct
9 Correct 9 ms 7680 KB Output is correct
10 Correct 9 ms 7552 KB Output is correct
11 Correct 9 ms 7552 KB Output is correct
12 Correct 10 ms 7552 KB Output is correct
13 Correct 9 ms 7472 KB Output is correct
14 Correct 9 ms 7424 KB Output is correct
15 Correct 9 ms 7424 KB Output is correct
16 Correct 9 ms 7424 KB Output is correct
17 Correct 9 ms 7552 KB Output is correct
18 Correct 9 ms 7552 KB Output is correct
19 Correct 9 ms 7552 KB Output is correct
20 Correct 9 ms 7552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 134 ms 48416 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 7552 KB Output is correct
2 Correct 10 ms 7680 KB Output is correct
3 Runtime error 719 ms 1048576 KB Execution killed with signal 9 (could be triggered by violating memory limits)
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 157 ms 47268 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 7424 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 7424 KB Output isn't correct
2 Halted 0 ms 0 KB -