Submission #1118731

# Submission time Handle Problem Language Result Execution time Memory
1118731 2024-11-26T04:10:36 Z boclobanchat Duathlon (APIO18_duathlon) C++14
31 / 100
130 ms 31868 KB
#include<bits/stdc++.h>
using namespace std;
#define ii pair<int,int>
#define fi first
#define se second
const int MAXN=1e5+5;
vector<int> ds[MAXN],sd[MAXN],vi[MAXN],ve[MAXN];
vector<ii> edge;
stack<int> st;
int low[MAXN],num[MAXN],col[MAXN],sub[MAXN],root[MAXN],tdfs=0,cnt=0;
long long ans=0,c=0,tp[MAXN],T[MAXN],tt[MAXN];
void dfs(int i,int pre)
{
	low[i]=num[i]=++tdfs;
	for(auto v:ds[i])
	{
		if(v==pre) continue;
		if(!num[v])
		{
			dfs(v,i);
			low[i]=min(low[i],low[v]);
			if(low[v]==num[v]) edge.push_back({i,v});
			else sd[i].push_back(v),sd[v].push_back(i);
		}
		else low[i]=min(low[i],num[v]),sd[i].push_back(v),sd[v].push_back(i);
	}
}
void dfsus(int i)
{
	c++,col[i]=cnt;
	for(auto v:sd[i]) if(!col[v]) dfsus(v);
}
void dftree(int i,int pre)
{
	st.push(i),sub[i]=1,root[i]=pre;
	for(auto v:vi[i]) if(v!=pre)
	{
		dftree(v,i);
		sub[i]+=sub[v],tp[i]+=tp[v];
	}
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=m;i++)
    {
    	int l,r;
    	cin>>l>>r;
    	ds[l].push_back(r),ds[r].push_back(l);
	}
	for(int i=1;i<=n;i++) if(!num[i]) dfs(i,i);
	for(int i=1;i<=n;i++) if(!col[i])
	{
		cnt++,c=0;
		dfsus(i);
		ans+=c*(c-1)*(c-2),tp[cnt]=T[cnt]=c;
	}
	for(auto v:edge)
	{
		vi[col[v.fi]].push_back(col[v.se]),vi[col[v.se]].push_back(col[v.fi]);
		ve[v.fi].push_back(v.se),ve[v.se].push_back(v.fi);
	}
	for(int i=1;i<=cnt;i++) if(!sub[i])
	{
		dftree(i,i);
		while(!st.empty()) tt[st.top()]=tp[i],st.pop();
	}
	for(int i=1;i<=cnt;i++)
	{
		ans+=T[i]*(tt[i]-T[i])*(tt[i]-T[i]);
		for(auto v:vi[i]) if(v==root[i]) ans-=T[i]*(tt[i]-tp[i])*(tt[i]-tp[i]);
		else ans-=T[i]*tp[v]*tp[v];
	}
	for(int i=1;i<=n;i++)
	{
		int cc=col[i];
		ans+=(T[cc]-1)*(tt[cc]-T[cc])*2;
		for(auto v:ve[i]) if(root[cc]==col[v]) ans-=(T[cc]-1)*(tt[cc]-tp[cc])*2;
		else ans-=(T[cc]-1)*tp[col[v]]*2;
	}
	cout<<ans;
}
# Verdict Execution time Memory Grader output
1 Correct 8 ms 9820 KB Output is correct
2 Correct 10 ms 9820 KB Output is correct
3 Correct 12 ms 9820 KB Output is correct
4 Correct 9 ms 10120 KB Output is correct
5 Correct 8 ms 9820 KB Output is correct
6 Correct 7 ms 9820 KB Output is correct
7 Incorrect 9 ms 9820 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 9820 KB Output is correct
2 Correct 10 ms 9820 KB Output is correct
3 Correct 12 ms 9820 KB Output is correct
4 Correct 9 ms 10120 KB Output is correct
5 Correct 8 ms 9820 KB Output is correct
6 Correct 7 ms 9820 KB Output is correct
7 Incorrect 9 ms 9820 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 112 ms 29336 KB Output is correct
2 Correct 98 ms 28564 KB Output is correct
3 Correct 113 ms 27148 KB Output is correct
4 Correct 96 ms 28368 KB Output is correct
5 Correct 113 ms 24524 KB Output is correct
6 Correct 93 ms 26340 KB Output is correct
7 Correct 92 ms 24120 KB Output is correct
8 Correct 79 ms 25804 KB Output is correct
9 Correct 79 ms 22480 KB Output is correct
10 Correct 102 ms 23588 KB Output is correct
11 Correct 67 ms 21720 KB Output is correct
12 Correct 62 ms 22012 KB Output is correct
13 Correct 63 ms 22208 KB Output is correct
14 Correct 62 ms 21408 KB Output is correct
15 Correct 49 ms 21444 KB Output is correct
16 Correct 91 ms 20932 KB Output is correct
17 Correct 16 ms 14328 KB Output is correct
18 Correct 14 ms 14172 KB Output is correct
19 Correct 13 ms 14172 KB Output is correct
20 Correct 14 ms 14172 KB Output is correct
21 Correct 13 ms 14172 KB Output is correct
22 Correct 12 ms 13964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 9820 KB Output is correct
2 Correct 8 ms 9820 KB Output is correct
3 Correct 9 ms 9820 KB Output is correct
4 Correct 8 ms 10076 KB Output is correct
5 Correct 7 ms 10076 KB Output is correct
6 Correct 7 ms 10076 KB Output is correct
7 Correct 7 ms 10064 KB Output is correct
8 Correct 7 ms 10064 KB Output is correct
9 Correct 8 ms 10064 KB Output is correct
10 Correct 11 ms 9808 KB Output is correct
11 Correct 7 ms 9808 KB Output is correct
12 Correct 8 ms 9864 KB Output is correct
13 Correct 11 ms 9808 KB Output is correct
14 Correct 8 ms 9808 KB Output is correct
15 Correct 9 ms 9808 KB Output is correct
16 Correct 8 ms 9808 KB Output is correct
17 Correct 8 ms 9808 KB Output is correct
18 Correct 9 ms 10068 KB Output is correct
19 Correct 10 ms 10048 KB Output is correct
20 Correct 11 ms 9808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 104 ms 26204 KB Output is correct
2 Correct 93 ms 25712 KB Output is correct
3 Correct 101 ms 25708 KB Output is correct
4 Correct 89 ms 25040 KB Output is correct
5 Correct 105 ms 25640 KB Output is correct
6 Correct 108 ms 31868 KB Output is correct
7 Correct 108 ms 29948 KB Output is correct
8 Correct 92 ms 28784 KB Output is correct
9 Correct 130 ms 27424 KB Output is correct
10 Correct 102 ms 26000 KB Output is correct
11 Correct 91 ms 25788 KB Output is correct
12 Correct 102 ms 25532 KB Output is correct
13 Correct 98 ms 25788 KB Output is correct
14 Correct 101 ms 24884 KB Output is correct
15 Correct 93 ms 24516 KB Output is correct
16 Correct 103 ms 21956 KB Output is correct
17 Correct 97 ms 26952 KB Output is correct
18 Correct 68 ms 26564 KB Output is correct
19 Correct 66 ms 27036 KB Output is correct
20 Correct 74 ms 27040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 9820 KB Output is correct
2 Correct 8 ms 9868 KB Output is correct
3 Incorrect 10 ms 9808 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 97 ms 25828 KB Output is correct
2 Correct 87 ms 25540 KB Output is correct
3 Incorrect 108 ms 23996 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 9820 KB Output is correct
2 Correct 10 ms 9820 KB Output is correct
3 Correct 12 ms 9820 KB Output is correct
4 Correct 9 ms 10120 KB Output is correct
5 Correct 8 ms 9820 KB Output is correct
6 Correct 7 ms 9820 KB Output is correct
7 Incorrect 9 ms 9820 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 9820 KB Output is correct
2 Correct 10 ms 9820 KB Output is correct
3 Correct 12 ms 9820 KB Output is correct
4 Correct 9 ms 10120 KB Output is correct
5 Correct 8 ms 9820 KB Output is correct
6 Correct 7 ms 9820 KB Output is correct
7 Incorrect 9 ms 9820 KB Output isn't correct
8 Halted 0 ms 0 KB -