Submission #414525

# Submission time Handle Problem Language Result Execution time Memory
414525 2021-05-30T15:09:55 Z hhhhaura Duathlon (APIO18_duathlon) C++14
23 / 100
1000 ms 30164 KB
#define wiwihorz
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma loop-opt(on)

#define rep(i, a, b) for(int i = a; i <= b; i++)
#define rrep(i, a, b) for(int i = b; i >= a; i--)
#define ceil(a, b) ((a + b - 1) / (b))
#define all(x) x.begin(), x.end()

#define INF 1000000000000000000
#define MOD 1000000007
#define eps (1e-9)

using namespace std;

#define int long long int
#define lld long double
#define pii pair<int, int>
#define random mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count())

#ifdef wiwihorz
#define print(a...) kout("[" + string(#a) + "] = ", a)
void vprint(auto L, auto R) { while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
void kout() { cerr << endl; }
template<class T1, class ... T2> void kout(T1 a, T2 ... e) { cerr << a << " ", kout(e...);}
#else
#define print(...) 0
#define vprint(...) 0
#endif
namespace solver {
	int n, timestamp, ii, bccid, ans, cnt;
	vector<int> L, D, pre, es, sz;
	vector<vector<int>> mp1, mp2;
	void init_(int _n) {
		n = _n, timestamp = 0;
		ii = 0, bccid = 0, ans = 0;
		L.assign(n + 1, 0);
		D.assign(n + 1, 0);
		pre.assign(n + 1, 0);
		mp1.assign(n + 1, vector<int>());
		mp2.assign(2 * n + 1, vector<int>());
		sz.assign(2 * n + 1, 0);
	}
	void add_edge(int a, int b) {
		mp1[a].push_back(es.size());
		mp1[b].push_back(es.size());
		es.push_back(a ^ b);
	}
	void dfs1(int x, int par) {
		cnt ++, pre[ii++] = x;
		L[x] = D[x] = ++timestamp;
		for(auto i : mp1[x]) if(i != par) {
			int to = es[i] ^ x;
			if(D[to]) L[x] = min(D[to], L[x]);
			else {
				dfs1(to, i);
				L[x] = min(L[x], L[to]);
				if(L[to] >= D[x]) {
					bccid ++;
					mp2[n + bccid].push_back(x);
					mp2[x].push_back(n + bccid);
					while(pre[ii] != to) {
						ii --;
						mp2[n + bccid].push_back(to);
						mp2[to].push_back(n + bccid);
					}
				}
			}
		}
		return;
	}
	void dfs2(int x, int par) {
		if(x <= n) sz[x] = 1;
		for(auto i : mp2[x]) if(i != par) {
			dfs2(i, x), sz[x] += sz[i];
			if(x > n) ans -= (mp2[x].size() - 1) * sz[i] * (sz[i] - 1);  
		} 
		if(x > n) ans -= (mp2[x].size() - 1) * (cnt - sz[x]) * (cnt - sz[x] - 1);
	}
	int solve() {
		rep(i, 1, n) if(!D[i]) {
			cnt = 0, dfs1(i, -1); 
			ans += cnt * (cnt - 1) * (cnt - 2);
			dfs2(i, i);
		}
		return ans;
	}
};
using namespace solver;
signed main() {
	ios::sync_with_stdio(false), cin.tie(0);
	int n, m; cin >> n >> m;
	init_(n);
	rep(i, 1, m) {
		int a, b; cin >> a >> b;
		add_edge(a, b);
	}
	cout << solve() << "\n";
	return 0;

}

Compilation message

count_triplets.cpp:4: warning: ignoring '#pragma loop ' [-Wunknown-pragmas]
    4 | #pragma loop-opt(on)
      | 
count_triplets.cpp:24:13: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   24 | void vprint(auto L, auto R) { while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
      |             ^~~~
count_triplets.cpp:24:21: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   24 | void vprint(auto L, auto R) { while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
      |                     ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 312 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 312 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Incorrect 1 ms 204 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 312 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 312 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Incorrect 1 ms 204 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1091 ms 28728 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 452 KB Output is correct
2 Correct 2 ms 460 KB Output is correct
3 Correct 2 ms 460 KB Output is correct
4 Correct 2 ms 588 KB Output is correct
5 Correct 2 ms 588 KB Output is correct
6 Correct 2 ms 588 KB Output is correct
7 Correct 2 ms 588 KB Output is correct
8 Correct 2 ms 588 KB Output is correct
9 Correct 2 ms 460 KB Output is correct
10 Correct 2 ms 460 KB Output is correct
11 Correct 2 ms 460 KB Output is correct
12 Correct 2 ms 460 KB Output is correct
13 Correct 2 ms 460 KB Output is correct
14 Correct 2 ms 460 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 1 ms 460 KB Output is correct
17 Correct 1 ms 460 KB Output is correct
18 Correct 1 ms 448 KB Output is correct
19 Correct 1 ms 460 KB Output is correct
20 Correct 1 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 121 ms 22892 KB Output is correct
2 Correct 127 ms 22944 KB Output is correct
3 Correct 125 ms 22932 KB Output is correct
4 Correct 121 ms 22888 KB Output is correct
5 Correct 120 ms 22916 KB Output is correct
6 Correct 129 ms 30164 KB Output is correct
7 Correct 145 ms 28076 KB Output is correct
8 Correct 144 ms 26772 KB Output is correct
9 Correct 130 ms 25408 KB Output is correct
10 Correct 120 ms 22840 KB Output is correct
11 Correct 136 ms 22864 KB Output is correct
12 Correct 125 ms 22840 KB Output is correct
13 Correct 134 ms 22880 KB Output is correct
14 Correct 115 ms 22048 KB Output is correct
15 Correct 102 ms 21232 KB Output is correct
16 Correct 82 ms 18308 KB Output is correct
17 Correct 86 ms 23264 KB Output is correct
18 Correct 97 ms 23220 KB Output is correct
19 Correct 97 ms 23604 KB Output is correct
20 Correct 101 ms 23224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 444 KB Output is correct
2 Correct 2 ms 460 KB Output is correct
3 Incorrect 2 ms 460 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 122 ms 22864 KB Output is correct
2 Correct 124 ms 22584 KB Output is correct
3 Incorrect 129 ms 22200 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 312 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 312 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Incorrect 1 ms 204 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 312 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 312 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Incorrect 1 ms 204 KB Output isn't correct
8 Halted 0 ms 0 KB -