답안 #517011

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
517011 2022-01-22T11:12:39 Z shmad 철인 이종 경기 (APIO18_duathlon) C++17
34 / 100
1000 ms 46040 KB
#pragma GCC optimize("O3", "unroll-loops")
#pragma GCC target("avx2", "bmi", "bmi2", "lzcnt", "popcnt") 

#include <bits/stdc++.h>

#define int long long
#define vt vector
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define ff first
#define ss second
#define dbg(x) cerr << #x << " = " << x << '\n'

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vvi = vt< vt<int> >;

const int N = 1e6 + 5, mod = 1e9 + 7, inf = 1e18 + 7, B = 500, LIM = (1ll << 60);
const double eps = 1e-6;

int n, m, sz;
vt<int> g[N], used(N), col(N);
bool ok, cycle;

void dfs (int v, int s, int c, int f, bool check = 0) {
	used[v] = 1;
	if (v == f) {
		ok |= check;
		return;
	}
	if (ok) return;
	if (v == c) check = 1;
	for (auto to: g[v]) {
		if (!used[to]) {
			dfs(to, s, c, f, check);
			used[to] = 0;
		}
	}
}

void dfs (int v, int p = -1) {
	col[v] = 1;
	sz++;
	for (auto to: g[v]) {
		if (to != p) {
			if (col[to] == 1) cycle = 1;
			if (col[to] == 0) dfs(to, v);
		}
	}
	col[v] = 2;
}

void solve_1 () {
	int ans = 0;
	used.resize(200);
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			for (int k = 1; k <= n; k++) {
				if (i == j || i == k || j == k) continue;
				ok = 0;
				fill(all(used), 0);
				dfs(i, i, j, k);
				if (ok) ans++;
			}
		}
	}
	cout << ans << '\n';
}

bool cum[51][51][51];

void paint (int v, int p, int colour) {
 	col[v] = colour;
 	for (auto to : g[v]) {
  		if (to != p && !col[to]) paint(to, p, colour);
	}
}

void solve_2 () {
	int ans = 0;
	for (int p = 1; p <= n; p++) {
		fill(all(col), 0);
		int colour = 0;
		for (int v = 1; v <= n; v++) {
			if (v != p && !col[v]) paint(v, p, ++colour);
		}
		for (int s = 1; s <= n; s++) {
			for (int c = 1; c <= n; c++) {
				if (c == p || col[c] == col[s]) continue;
				for (int f = 1; f <= n; f++) {
					if (f == s || col[f] == col[c] || cum[s][f][c]) continue;
					ans--;
					cum[s][f][c] = 1;
				}
			}
		}
	}
	ans += (n * (n - 1) * (n - 2));
	cout << ans << '\n';
}

void solve_3 () {
    int ans = 0;
	for (int i = 1; i <= n; i++) {
		if (!col[i]) {
			sz = cycle = 0;
			dfs(i);
			int x = sz * (sz - 1) * (sz - 2);
			if (!cycle) x /= 3;
			ans += x;
		}
	}
	cout << ans << '\n';	
}

void solve_4 () {
	int ans = 0;
	for (int s = 1; s <= n; s++) {
		queue<int> q;
		vt<int> d(n + 1, inf);
		q.push(s);
		d[s] = 0;
		while (!q.empty()) {
			int v = q.front();
			q.pop();
			for (auto to: g[v]) {
			 	if (d[to] > d[v] + 1) {
			 		d[to] = d[v] + 1;
			 		q.push(to);
			 	}
			}
		}
		for (int i = 1; i <= n; i++) {
			if (i != s && d[i] != inf) ans += d[i] - 1;
		}
	}
	cout << ans << '\n';
}

void solve () {
	cin >> n >> m;
	bool sub1 = (n <= 10 && m <= 100), sub2 = (n <= 50 && m <= 100), sub3 = 1;
	for (int i = 1; i <= m; i++) {
		int x, y;
		cin >> x >> y;
		g[x].pb(y);
		g[y].pb(x);
		if (max(sz(g[x]), sz(g[y])) > 2) sub3 = 0;
	}     
	if (sub1) {
		solve_1();
		return;
	}
	if (sub2) {
	 	solve_2();
	 	return;
	}
	if (sub3) {
		solve_3();
		return;
	}
	solve_4();
	cout << '\n';
}

bool testcases = 0;
                  
signed main() {
#ifdef ONLINE_JUDGE
	freopen(".in", "r", stdin);
	freopen(".out", "w", stdout);
#endif
    cin.tie(0) -> sync_with_stdio(0);
    int test = 1;
    if (testcases) cin >> test;
    for (int cs = 1; cs <= test; cs++) {
        solve();
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 39364 KB Output is correct
2 Correct 19 ms 39368 KB Output is correct
3 Correct 20 ms 39420 KB Output is correct
4 Correct 21 ms 39372 KB Output is correct
5 Correct 20 ms 39372 KB Output is correct
6 Correct 19 ms 39372 KB Output is correct
7 Correct 19 ms 39372 KB Output is correct
8 Correct 19 ms 39456 KB Output is correct
9 Correct 19 ms 39448 KB Output is correct
10 Correct 19 ms 39372 KB Output is correct
11 Correct 18 ms 39372 KB Output is correct
12 Correct 18 ms 39372 KB Output is correct
13 Correct 20 ms 39428 KB Output is correct
14 Correct 28 ms 39460 KB Output is correct
15 Correct 18 ms 39372 KB Output is correct
16 Correct 19 ms 39436 KB Output is correct
17 Correct 23 ms 39360 KB Output is correct
18 Correct 19 ms 39364 KB Output is correct
19 Correct 18 ms 39372 KB Output is correct
20 Correct 19 ms 39436 KB Output is correct
21 Correct 18 ms 39424 KB Output is correct
22 Correct 25 ms 39372 KB Output is correct
23 Correct 20 ms 39456 KB Output is correct
24 Correct 25 ms 39372 KB Output is correct
25 Correct 21 ms 39372 KB Output is correct
26 Correct 20 ms 39456 KB Output is correct
27 Correct 19 ms 39392 KB Output is correct
28 Correct 20 ms 39448 KB Output is correct
29 Correct 20 ms 39372 KB Output is correct
30 Correct 20 ms 39372 KB Output is correct
31 Correct 20 ms 39364 KB Output is correct
32 Correct 20 ms 39452 KB Output is correct
33 Correct 20 ms 39412 KB Output is correct
34 Correct 22 ms 39428 KB Output is correct
35 Correct 19 ms 39416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 39364 KB Output is correct
2 Correct 19 ms 39368 KB Output is correct
3 Correct 20 ms 39420 KB Output is correct
4 Correct 21 ms 39372 KB Output is correct
5 Correct 20 ms 39372 KB Output is correct
6 Correct 19 ms 39372 KB Output is correct
7 Correct 19 ms 39372 KB Output is correct
8 Correct 19 ms 39456 KB Output is correct
9 Correct 19 ms 39448 KB Output is correct
10 Correct 19 ms 39372 KB Output is correct
11 Correct 18 ms 39372 KB Output is correct
12 Correct 18 ms 39372 KB Output is correct
13 Correct 20 ms 39428 KB Output is correct
14 Correct 28 ms 39460 KB Output is correct
15 Correct 18 ms 39372 KB Output is correct
16 Correct 19 ms 39436 KB Output is correct
17 Correct 23 ms 39360 KB Output is correct
18 Correct 19 ms 39364 KB Output is correct
19 Correct 18 ms 39372 KB Output is correct
20 Correct 19 ms 39436 KB Output is correct
21 Correct 18 ms 39424 KB Output is correct
22 Correct 25 ms 39372 KB Output is correct
23 Correct 20 ms 39456 KB Output is correct
24 Correct 25 ms 39372 KB Output is correct
25 Correct 21 ms 39372 KB Output is correct
26 Correct 20 ms 39456 KB Output is correct
27 Correct 19 ms 39392 KB Output is correct
28 Correct 20 ms 39448 KB Output is correct
29 Correct 20 ms 39372 KB Output is correct
30 Correct 20 ms 39372 KB Output is correct
31 Correct 20 ms 39364 KB Output is correct
32 Correct 20 ms 39452 KB Output is correct
33 Correct 20 ms 39412 KB Output is correct
34 Correct 22 ms 39428 KB Output is correct
35 Correct 19 ms 39416 KB Output is correct
36 Correct 64 ms 39580 KB Output is correct
37 Correct 68 ms 39584 KB Output is correct
38 Correct 58 ms 39556 KB Output is correct
39 Correct 56 ms 39584 KB Output is correct
40 Correct 62 ms 39588 KB Output is correct
41 Correct 59 ms 39584 KB Output is correct
42 Correct 59 ms 39524 KB Output is correct
43 Correct 58 ms 39576 KB Output is correct
44 Correct 60 ms 39576 KB Output is correct
45 Correct 71 ms 39596 KB Output is correct
46 Correct 56 ms 39572 KB Output is correct
47 Correct 20 ms 39464 KB Output is correct
48 Correct 57 ms 39500 KB Output is correct
49 Correct 57 ms 39480 KB Output is correct
50 Correct 59 ms 39560 KB Output is correct
51 Correct 51 ms 39500 KB Output is correct
52 Correct 45 ms 39468 KB Output is correct
53 Correct 55 ms 39452 KB Output is correct
54 Correct 43 ms 39576 KB Output is correct
55 Correct 44 ms 39464 KB Output is correct
56 Correct 53 ms 39584 KB Output is correct
57 Correct 43 ms 39504 KB Output is correct
58 Correct 44 ms 39588 KB Output is correct
59 Correct 67 ms 39484 KB Output is correct
60 Correct 59 ms 39572 KB Output is correct
61 Correct 57 ms 39592 KB Output is correct
62 Correct 59 ms 39500 KB Output is correct
63 Correct 44 ms 39520 KB Output is correct
64 Correct 47 ms 39500 KB Output is correct
65 Correct 50 ms 39500 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 58 ms 45984 KB Output is correct
2 Correct 70 ms 46040 KB Output is correct
3 Correct 59 ms 44284 KB Output is correct
4 Correct 57 ms 45148 KB Output is correct
5 Correct 63 ms 43716 KB Output is correct
6 Correct 69 ms 43672 KB Output is correct
7 Correct 66 ms 43240 KB Output is correct
8 Correct 56 ms 43500 KB Output is correct
9 Correct 62 ms 42800 KB Output is correct
10 Correct 63 ms 43204 KB Output is correct
11 Correct 49 ms 42552 KB Output is correct
12 Correct 48 ms 42360 KB Output is correct
13 Correct 47 ms 42456 KB Output is correct
14 Correct 54 ms 42256 KB Output is correct
15 Correct 49 ms 41896 KB Output is correct
16 Correct 39 ms 41800 KB Output is correct
17 Correct 20 ms 39412 KB Output is correct
18 Correct 20 ms 39444 KB Output is correct
19 Correct 20 ms 39428 KB Output is correct
20 Correct 24 ms 39380 KB Output is correct
21 Correct 20 ms 39372 KB Output is correct
22 Correct 20 ms 39408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 39392 KB Output is correct
2 Correct 38 ms 39472 KB Output is correct
3 Correct 44 ms 39488 KB Output is correct
4 Correct 23 ms 39500 KB Output is correct
5 Correct 40 ms 39456 KB Output is correct
6 Correct 41 ms 39500 KB Output is correct
7 Correct 25 ms 39476 KB Output is correct
8 Correct 44 ms 39628 KB Output is correct
9 Correct 40 ms 39472 KB Output is correct
10 Correct 37 ms 39500 KB Output is correct
11 Correct 34 ms 39484 KB Output is correct
12 Correct 36 ms 39492 KB Output is correct
13 Correct 32 ms 39468 KB Output is correct
14 Correct 23 ms 39412 KB Output is correct
15 Correct 21 ms 39472 KB Output is correct
16 Correct 28 ms 39500 KB Output is correct
17 Correct 29 ms 39428 KB Output is correct
18 Correct 29 ms 39480 KB Output is correct
19 Correct 29 ms 39468 KB Output is correct
20 Correct 30 ms 39528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1091 ms 44092 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 39500 KB Output is correct
2 Correct 38 ms 39496 KB Output is correct
3 Incorrect 38 ms 39468 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1071 ms 44064 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 39364 KB Output is correct
2 Correct 19 ms 39368 KB Output is correct
3 Correct 20 ms 39420 KB Output is correct
4 Correct 21 ms 39372 KB Output is correct
5 Correct 20 ms 39372 KB Output is correct
6 Correct 19 ms 39372 KB Output is correct
7 Correct 19 ms 39372 KB Output is correct
8 Correct 19 ms 39456 KB Output is correct
9 Correct 19 ms 39448 KB Output is correct
10 Correct 19 ms 39372 KB Output is correct
11 Correct 18 ms 39372 KB Output is correct
12 Correct 18 ms 39372 KB Output is correct
13 Correct 20 ms 39428 KB Output is correct
14 Correct 28 ms 39460 KB Output is correct
15 Correct 18 ms 39372 KB Output is correct
16 Correct 19 ms 39436 KB Output is correct
17 Correct 23 ms 39360 KB Output is correct
18 Correct 19 ms 39364 KB Output is correct
19 Correct 18 ms 39372 KB Output is correct
20 Correct 19 ms 39436 KB Output is correct
21 Correct 18 ms 39424 KB Output is correct
22 Correct 25 ms 39372 KB Output is correct
23 Correct 20 ms 39456 KB Output is correct
24 Correct 25 ms 39372 KB Output is correct
25 Correct 21 ms 39372 KB Output is correct
26 Correct 20 ms 39456 KB Output is correct
27 Correct 19 ms 39392 KB Output is correct
28 Correct 20 ms 39448 KB Output is correct
29 Correct 20 ms 39372 KB Output is correct
30 Correct 20 ms 39372 KB Output is correct
31 Correct 20 ms 39364 KB Output is correct
32 Correct 20 ms 39452 KB Output is correct
33 Correct 20 ms 39412 KB Output is correct
34 Correct 22 ms 39428 KB Output is correct
35 Correct 19 ms 39416 KB Output is correct
36 Correct 64 ms 39580 KB Output is correct
37 Correct 68 ms 39584 KB Output is correct
38 Correct 58 ms 39556 KB Output is correct
39 Correct 56 ms 39584 KB Output is correct
40 Correct 62 ms 39588 KB Output is correct
41 Correct 59 ms 39584 KB Output is correct
42 Correct 59 ms 39524 KB Output is correct
43 Correct 58 ms 39576 KB Output is correct
44 Correct 60 ms 39576 KB Output is correct
45 Correct 71 ms 39596 KB Output is correct
46 Correct 56 ms 39572 KB Output is correct
47 Correct 20 ms 39464 KB Output is correct
48 Correct 57 ms 39500 KB Output is correct
49 Correct 57 ms 39480 KB Output is correct
50 Correct 59 ms 39560 KB Output is correct
51 Correct 51 ms 39500 KB Output is correct
52 Correct 45 ms 39468 KB Output is correct
53 Correct 55 ms 39452 KB Output is correct
54 Correct 43 ms 39576 KB Output is correct
55 Correct 44 ms 39464 KB Output is correct
56 Correct 53 ms 39584 KB Output is correct
57 Correct 43 ms 39504 KB Output is correct
58 Correct 44 ms 39588 KB Output is correct
59 Correct 67 ms 39484 KB Output is correct
60 Correct 59 ms 39572 KB Output is correct
61 Correct 57 ms 39592 KB Output is correct
62 Correct 59 ms 39500 KB Output is correct
63 Correct 44 ms 39520 KB Output is correct
64 Correct 47 ms 39500 KB Output is correct
65 Correct 50 ms 39500 KB Output is correct
66 Correct 19 ms 39408 KB Output is correct
67 Correct 22 ms 39460 KB Output is correct
68 Incorrect 40 ms 39416 KB Output isn't correct
69 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 39364 KB Output is correct
2 Correct 19 ms 39368 KB Output is correct
3 Correct 20 ms 39420 KB Output is correct
4 Correct 21 ms 39372 KB Output is correct
5 Correct 20 ms 39372 KB Output is correct
6 Correct 19 ms 39372 KB Output is correct
7 Correct 19 ms 39372 KB Output is correct
8 Correct 19 ms 39456 KB Output is correct
9 Correct 19 ms 39448 KB Output is correct
10 Correct 19 ms 39372 KB Output is correct
11 Correct 18 ms 39372 KB Output is correct
12 Correct 18 ms 39372 KB Output is correct
13 Correct 20 ms 39428 KB Output is correct
14 Correct 28 ms 39460 KB Output is correct
15 Correct 18 ms 39372 KB Output is correct
16 Correct 19 ms 39436 KB Output is correct
17 Correct 23 ms 39360 KB Output is correct
18 Correct 19 ms 39364 KB Output is correct
19 Correct 18 ms 39372 KB Output is correct
20 Correct 19 ms 39436 KB Output is correct
21 Correct 18 ms 39424 KB Output is correct
22 Correct 25 ms 39372 KB Output is correct
23 Correct 20 ms 39456 KB Output is correct
24 Correct 25 ms 39372 KB Output is correct
25 Correct 21 ms 39372 KB Output is correct
26 Correct 20 ms 39456 KB Output is correct
27 Correct 19 ms 39392 KB Output is correct
28 Correct 20 ms 39448 KB Output is correct
29 Correct 20 ms 39372 KB Output is correct
30 Correct 20 ms 39372 KB Output is correct
31 Correct 20 ms 39364 KB Output is correct
32 Correct 20 ms 39452 KB Output is correct
33 Correct 20 ms 39412 KB Output is correct
34 Correct 22 ms 39428 KB Output is correct
35 Correct 19 ms 39416 KB Output is correct
36 Correct 64 ms 39580 KB Output is correct
37 Correct 68 ms 39584 KB Output is correct
38 Correct 58 ms 39556 KB Output is correct
39 Correct 56 ms 39584 KB Output is correct
40 Correct 62 ms 39588 KB Output is correct
41 Correct 59 ms 39584 KB Output is correct
42 Correct 59 ms 39524 KB Output is correct
43 Correct 58 ms 39576 KB Output is correct
44 Correct 60 ms 39576 KB Output is correct
45 Correct 71 ms 39596 KB Output is correct
46 Correct 56 ms 39572 KB Output is correct
47 Correct 20 ms 39464 KB Output is correct
48 Correct 57 ms 39500 KB Output is correct
49 Correct 57 ms 39480 KB Output is correct
50 Correct 59 ms 39560 KB Output is correct
51 Correct 51 ms 39500 KB Output is correct
52 Correct 45 ms 39468 KB Output is correct
53 Correct 55 ms 39452 KB Output is correct
54 Correct 43 ms 39576 KB Output is correct
55 Correct 44 ms 39464 KB Output is correct
56 Correct 53 ms 39584 KB Output is correct
57 Correct 43 ms 39504 KB Output is correct
58 Correct 44 ms 39588 KB Output is correct
59 Correct 67 ms 39484 KB Output is correct
60 Correct 59 ms 39572 KB Output is correct
61 Correct 57 ms 39592 KB Output is correct
62 Correct 59 ms 39500 KB Output is correct
63 Correct 44 ms 39520 KB Output is correct
64 Correct 47 ms 39500 KB Output is correct
65 Correct 50 ms 39500 KB Output is correct
66 Correct 58 ms 45984 KB Output is correct
67 Correct 70 ms 46040 KB Output is correct
68 Correct 59 ms 44284 KB Output is correct
69 Correct 57 ms 45148 KB Output is correct
70 Correct 63 ms 43716 KB Output is correct
71 Correct 69 ms 43672 KB Output is correct
72 Correct 66 ms 43240 KB Output is correct
73 Correct 56 ms 43500 KB Output is correct
74 Correct 62 ms 42800 KB Output is correct
75 Correct 63 ms 43204 KB Output is correct
76 Correct 49 ms 42552 KB Output is correct
77 Correct 48 ms 42360 KB Output is correct
78 Correct 47 ms 42456 KB Output is correct
79 Correct 54 ms 42256 KB Output is correct
80 Correct 49 ms 41896 KB Output is correct
81 Correct 39 ms 41800 KB Output is correct
82 Correct 20 ms 39412 KB Output is correct
83 Correct 20 ms 39444 KB Output is correct
84 Correct 20 ms 39428 KB Output is correct
85 Correct 24 ms 39380 KB Output is correct
86 Correct 20 ms 39372 KB Output is correct
87 Correct 20 ms 39408 KB Output is correct
88 Correct 36 ms 39392 KB Output is correct
89 Correct 38 ms 39472 KB Output is correct
90 Correct 44 ms 39488 KB Output is correct
91 Correct 23 ms 39500 KB Output is correct
92 Correct 40 ms 39456 KB Output is correct
93 Correct 41 ms 39500 KB Output is correct
94 Correct 25 ms 39476 KB Output is correct
95 Correct 44 ms 39628 KB Output is correct
96 Correct 40 ms 39472 KB Output is correct
97 Correct 37 ms 39500 KB Output is correct
98 Correct 34 ms 39484 KB Output is correct
99 Correct 36 ms 39492 KB Output is correct
100 Correct 32 ms 39468 KB Output is correct
101 Correct 23 ms 39412 KB Output is correct
102 Correct 21 ms 39472 KB Output is correct
103 Correct 28 ms 39500 KB Output is correct
104 Correct 29 ms 39428 KB Output is correct
105 Correct 29 ms 39480 KB Output is correct
106 Correct 29 ms 39468 KB Output is correct
107 Correct 30 ms 39528 KB Output is correct
108 Execution timed out 1091 ms 44092 KB Time limit exceeded
109 Halted 0 ms 0 KB -