답안 #172182

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
172182 2019-12-31T14:11:08 Z dndhk 철인 이종 경기 (APIO18_duathlon) C++14
0 / 100
215 ms 32240 KB
#include <bits/stdc++.h>

#define all(v) (v).begin(), (v).end()
#define sortv(v) sort(all(v))
#define uniqv(v) (v).erase(unique(all(v)), (v).end())
#define pb push_back
#define FI first
#define SE second
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define test 0
#define TEST if(test)

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

const int MOD = 1000000007; // 998244353
const int INF = 2e9;
const ll INFLL = 1e18;
const int MAX_N = 100000;

int N, M;
vector<int> gp[MAX_N+1];
int dfsn[MAX_N+1], up[MAX_N+1], p[MAX_N+1], cnt;
int sz2[MAX_N+1];

void dfs(int x){
	sz2[x] = 1;
	dfsn[x] = up[x] = ++cnt;
	for(int i : gp[x]){
		if(i==p[x])	continue;
		if(dfsn[i]==0){
			p[i] = x;
			dfs(i);
			sz2[x]+=sz2[i];
			up[x] = min(up[x], up[i]);
		}else{
			up[x] = min(up[x], dfsn[i]);
		}
	}
}

vector<int> BCC[MAX_N+1];
vector<int> cl[MAX_N+1];
vector<pii> sz[MAX_N+1];
bool vst[MAX_N+1];
int sz3[MAX_N+1];
vector<pii> sz4[MAX_N+1];

void color(int x, int y){
	if(y>0){
		BCC[y].pb(x);
		cl[x].pb(y);
	}
	vst[x] = true;
	bool tf = false;
	int sum = 0;
	for(int i : gp[x]){
		if(vst[i])	continue;
		if(dfsn[x]<=up[i]){
			tf = true;
			BCC[++cnt].pb(x);
			if(N-sz2[i]-1!=0)	{
				sz[cnt].pb({x, N - sz2[i] - 1});
				sz4[x].pb({cnt, sz2[i]});
			}
			sum += sz2[i] - 1;
			cl[x].pb(cnt);
			color(i, cnt);
		}else{
			color(i, y);
		}
	}
	if(tf && y>0){
		sz[y].pb({x, sum});
		sz4[y].pb({y, N - 1 - sum});
	}
}

ll ans;
ll calc[MAX_N+1];

int main(){
	scanf("%d%d", &N, &M);
	for(int i=1; i<=M; i++){
		int a, b; scanf("%d%d", &a, &b);
		gp[a].pb(b); gp[b].pb(a);
	}
	dfs(1); cnt = 0; color(1, 0);
	for(int i=1; i<=N; i++){
		calc[i] = 1;
		for(int j : cl[i]){
			sz3[i] += (BCC[j].size() - 1);
		}
		TEST cout<<i<<" "<<sz3[i]<<endl;
		ans += (ll)sz3[i] * (ll)(sz3[i]-1);
	}
	for(int i=1; i<=cnt; i++){
		// type 2
		ll sum1 = 0, sum2 = 0;
		ll num = 0;
		TEST cout<<i<<endl;
		for(int j : BCC[i]){
			TEST cout<<j<<" ";
			if(cl[j].size()==1)	num++;
		}
		TEST cout<<endl;
		TEST cout<<num<<endl;
		ans += num * (num-1) * (ll)(N - BCC[i].size()) * 2LL;
		for(pii j : sz[i]){
			sum2 += sum1 * (ll)j.second;
			sum1 += (ll)j.second;
			ans += 2LL * num * (ll)(N - BCC[i].size() - j.second);
			TEST cout<<j.first<<" "<<j.second<<endl;
			TEST cout<<(N-BCC[i].size() -j.second)<<endl;
			ans += 2LL * (ll)(BCC[i].size()-1) * (ll)(j.second - sz3[j.first] + BCC[i].size() - 1);
		}
		TEST cout<<num<<" "<<sum2<<endl;
		ans += num * 2LL * sum2;
	}
	for(int i=1; i<=N; i++){
		if(cl[i].size()>1){
			ll sum1 = 0, sum2 = 0;
			for(pii j : sz4[i]){
				sum2 += (ll)(j.second - BCC[j.first].size() + 1) * sum1;
				sum1 += (ll)(j.second - BCC[j.first].size() + 1);
			}
			ans += sum2;
		}
	}
	cout<<ans;
	return 0;
}

Compilation message

count_triplets.cpp: In function 'int main()':
count_triplets.cpp:89:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &N, &M);
  ~~~~~^~~~~~~~~~~~~~~~
count_triplets.cpp:91:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int a, b; scanf("%d%d", &a, &b);
             ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 13 ms 12280 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 13 ms 12280 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 134 ms 32208 KB Output is correct
2 Correct 151 ms 32240 KB Output is correct
3 Incorrect 103 ms 25672 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 14 ms 12280 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 215 ms 31864 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 14 ms 12280 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 194 ms 31656 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 13 ms 12280 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 13 ms 12280 KB Output isn't correct
2 Halted 0 ms 0 KB -