Submission #265014

# Submission time Handle Problem Language Result Execution time Memory
265014 2020-08-14T12:22:37 Z dsjong Duathlon (APIO18_duathlon) C++14
31 / 100
91 ms 13168 KB
#include<bits/stdc++.h>
using namespace std;
vector<int>adj[100005];
bool vis[100005];
long long cnt=0;
bool bb=true;
int des[100005];
int par[100005];
vector<int>v;
void dfs(int i){
	v.push_back(i);
	if(adj[i].size()==1) bb=false;
	cnt++;
	vis[i]=true;
	for(int j:adj[i]){
		if(!vis[j]){
			par[j]=i;
			dfs(j);
			des[i]+=des[j];
		}
	}
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		int x,y;
		cin>>x>>y;
		adj[x].push_back(y);
		adj[y].push_back(x);
	}
	for(int i=1;i<=n;i++){
		par[i]=0;
		des[i]=1;
	}
	long long ans=0;
	for(int i=1;i<=n;i++){
		if(!vis[i]){
			cnt=0;
			v.clear();
			bb=true;
			dfs(i);
			if(bb) ans=ans+((long long)(cnt)*(cnt-1)*(cnt-2));
			else{
				long long res=0;
				for(int j:v){
					for(int k:adj[j]){
						if(k==par[j]){
							res+=(cnt-des[j])*(cnt-des[j]);
						}
						else{
							res+=((long long)des[k])*des[k];
						}
						//cout<<res<<" ";
					}
				}
				ans=ans+cnt*(cnt-1)*(cnt-1)-res;
				//ans=ans+((long long)(cnt)*(cnt-1)*(cnt-2)/3);
			}
		}
	}
	cout<<ans;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Correct 2 ms 2688 KB Output is correct
3 Correct 2 ms 2688 KB Output is correct
4 Correct 2 ms 2688 KB Output is correct
5 Correct 2 ms 2688 KB Output is correct
6 Correct 2 ms 2688 KB Output is correct
7 Incorrect 2 ms 2688 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Correct 2 ms 2688 KB Output is correct
3 Correct 2 ms 2688 KB Output is correct
4 Correct 2 ms 2688 KB Output is correct
5 Correct 2 ms 2688 KB Output is correct
6 Correct 2 ms 2688 KB Output is correct
7 Incorrect 2 ms 2688 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 91 ms 13168 KB Output is correct
2 Correct 90 ms 13136 KB Output is correct
3 Correct 90 ms 10612 KB Output is correct
4 Correct 91 ms 11888 KB Output is correct
5 Correct 79 ms 9848 KB Output is correct
6 Correct 71 ms 9848 KB Output is correct
7 Correct 78 ms 9080 KB Output is correct
8 Correct 81 ms 9460 KB Output is correct
9 Correct 74 ms 8440 KB Output is correct
10 Correct 72 ms 9080 KB Output is correct
11 Correct 65 ms 7672 KB Output is correct
12 Correct 61 ms 7612 KB Output is correct
13 Correct 45 ms 7544 KB Output is correct
14 Correct 53 ms 7380 KB Output is correct
15 Correct 49 ms 6748 KB Output is correct
16 Correct 42 ms 6776 KB Output is correct
17 Correct 4 ms 3584 KB Output is correct
18 Correct 5 ms 3584 KB Output is correct
19 Correct 3 ms 3584 KB Output is correct
20 Correct 3 ms 3584 KB Output is correct
21 Correct 4 ms 3584 KB Output is correct
22 Correct 7 ms 3584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2688 KB Output is correct
2 Correct 2 ms 2816 KB Output is correct
3 Correct 3 ms 2816 KB Output is correct
4 Correct 2 ms 2816 KB Output is correct
5 Correct 3 ms 2816 KB Output is correct
6 Correct 2 ms 2816 KB Output is correct
7 Correct 2 ms 2816 KB Output is correct
8 Correct 2 ms 2816 KB Output is correct
9 Correct 3 ms 2816 KB Output is correct
10 Correct 2 ms 2688 KB Output is correct
11 Correct 2 ms 2688 KB Output is correct
12 Correct 2 ms 2816 KB Output is correct
13 Correct 3 ms 2816 KB Output is correct
14 Correct 2 ms 2688 KB Output is correct
15 Correct 2 ms 2688 KB Output is correct
16 Correct 2 ms 2688 KB Output is correct
17 Correct 2 ms 2816 KB Output is correct
18 Correct 3 ms 2688 KB Output is correct
19 Correct 2 ms 2816 KB Output is correct
20 Correct 2 ms 2816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 61 ms 8716 KB Output is correct
2 Correct 65 ms 8692 KB Output is correct
3 Correct 75 ms 8692 KB Output is correct
4 Correct 71 ms 8692 KB Output is correct
5 Correct 66 ms 8692 KB Output is correct
6 Correct 80 ms 11200 KB Output is correct
7 Correct 74 ms 10224 KB Output is correct
8 Correct 76 ms 9844 KB Output is correct
9 Correct 73 ms 9592 KB Output is correct
10 Correct 65 ms 8440 KB Output is correct
11 Correct 66 ms 8692 KB Output is correct
12 Correct 64 ms 8312 KB Output is correct
13 Correct 67 ms 8312 KB Output is correct
14 Correct 57 ms 7800 KB Output is correct
15 Correct 56 ms 7544 KB Output is correct
16 Correct 34 ms 6520 KB Output is correct
17 Correct 41 ms 9072 KB Output is correct
18 Correct 41 ms 8944 KB Output is correct
19 Correct 43 ms 9076 KB Output is correct
20 Correct 40 ms 8948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Correct 2 ms 2816 KB Output is correct
3 Incorrect 2 ms 2688 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 62 ms 8696 KB Output is correct
2 Correct 86 ms 8696 KB Output is correct
3 Incorrect 83 ms 8824 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Correct 2 ms 2688 KB Output is correct
3 Correct 2 ms 2688 KB Output is correct
4 Correct 2 ms 2688 KB Output is correct
5 Correct 2 ms 2688 KB Output is correct
6 Correct 2 ms 2688 KB Output is correct
7 Incorrect 2 ms 2688 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Correct 2 ms 2688 KB Output is correct
3 Correct 2 ms 2688 KB Output is correct
4 Correct 2 ms 2688 KB Output is correct
5 Correct 2 ms 2688 KB Output is correct
6 Correct 2 ms 2688 KB Output is correct
7 Incorrect 2 ms 2688 KB Output isn't correct
8 Halted 0 ms 0 KB -