제출 #104313

#제출 시각아이디문제언어결과실행 시간메모리
104313dimash241Duathlon (APIO18_duathlon)C++14
100 / 100
324 ms66628 KiB
# include <stdio.h>
# include <bits/stdc++.h>


#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define For(i,x,y)  for (int i = x; i <= y; i ++) 
#define FOr(i,x,y)  for (int i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
// ROAD to...                                                                                                                                                                                                                Red

using namespace std;
inline double Time() {return (clock() * 1.0) / CLOCKS_PER_SEC; } 
inline bool isvowel (char c) {
	c = tolower(c);
    if (c == 'a' || c == 'e' || c == 'i' || c == 'y' || c == 'o' || c == 'u') return 1;
    return 0;
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 6e5 + 123;                                          
const int M = 22;
const int pri = 997;
const int Magic = 2101;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
 
int n, m, k;
vector < int > g[N], st, gr[N];
vector < int > comp[N];
int len;
ll ans;
int timer;
ll sz[N];
int fup[N], tin[N];

void dfs (int v, int pr = 0) {
	fup[v] = tin[v] = ++ timer;
	st.pb(v);
	
	for (auto to : g[v]) {
		if (pr == to) continue;
		if (tin[to]) {
			fup[v] = min(fup[v], tin[to]);
		} else {	
			dfs(to, v);
			fup[v] = min(fup[v], fup[to]);
			if (fup[to] >= tin[v]) {
				vector < int > cur;
				cur.pb(v);
				while (cur.back() != to) {
					cur.pb(st.back());
					st.pop_back();
				}
				
				comp[len ++] = cur;
			}
		}
	}
}

int u[N];
void calc (int v, int par) {
	u[v] = 1;
	if (v <= n) sz[v] = 1;
	else sz[v] = 0;
	for (auto to : gr[v]) {
		if (to != par) {
			calc (to, v);
			sz[v] += sz[to];
		}
	}
}
   
void rem (int v, int pr, ll M) {
	u[v] = 1;
	if (v <= n) {
		for (auto to : gr[v]) {
			if (to == pr) ans -= sz[v] * (sz[v] - 1ll) * (ll)(comp[to - n - 1].size() - 1);
			else ans -= (M - sz[to]) * (M - sz[to] - 1) * (ll)(comp[to - n - 1].size() - 1);; 
		}
		
	}
	for (auto to : gr[v]) {
		if (to != pr)
			rem(to, v, M);
	}
}

int main () {               
	SpeedForce;

    cin >> n >> m;
    for (int i = 1; i <= m; i ++) {
    	int l, r;
    	cin >> l >> r;
    	g[l].pb(r);
    	g[r].pb(l);
    }

    for (int i = 1; i <= n; i ++) {
    	if (!tin[i]) {
    		dfs(i);
    		while (st.size()) {
    			comp[len ++] = {st.back()};
    			st.pop_back();	
    		}
    	}
    }
    for (int i = 0; i < len; i ++) {
    	for (int j = 0; j < comp[i].size(); j ++) {
    		gr[comp[i][j]].pb(n + i + 1);
    		gr[n + i + 1].pb(comp[i][j]);
    	}
    
    }

    for (int i = 1; i <= n; i ++) {
    	if (!u[i]) {
    		calc (i, 0);
   // 		cout << "<< i << ' ' << sz[i] << '\n';
    		ans += sz[i] * (sz[i] - 1ll) * (sz[i] - 2ll);
    		rem (i, 0, sz[i]);
    	}
    }
    

    cout << ans;

    return Accepted;
}

// B...a D....

컴파일 시 표준 에러 (stderr) 메시지

count_triplets.cpp: In function 'int main()':
count_triplets.cpp:127:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
      for (int j = 0; j < comp[i].size(); j ++) {
                      ~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...