답안 #233851

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
233851 2020-05-22T01:49:52 Z gs18115 철인 이종 경기 (APIO18_duathlon) C++14
0 / 100
909 ms 1048580 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;
            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 98 ms 30120 KB Output is correct
2 Correct 107 ms 30056 KB Output is correct
3 Runtime error 137 ms 54092 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 7544 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 10 ms 7680 KB Output is correct
6 Correct 10 ms 7680 KB Output is correct
7 Correct 10 ms 7680 KB Output is correct
8 Correct 10 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 9 ms 7552 KB Output is correct
13 Correct 9 ms 7424 KB Output is correct
14 Incorrect 9 ms 7424 KB Output isn't correct
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 136 ms 48560 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 7552 KB Output is correct
2 Correct 9 ms 7552 KB Output is correct
3 Runtime error 909 ms 1048580 KB Execution killed with signal 9 (could be triggered by violating memory limits)
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 143 ms 48420 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 -