Submission #516947

#TimeUsernameProblemLanguageResultExecution timeMemory
516947shmad철인 이종 경기 (APIO18_duathlon)C++17
0 / 100
51 ms80004 KiB
#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 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 () {
	int n, m;
	cin >> n >> m;
	bool 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;
	}
	int ans = 0;
	if (sub3) {
		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';
		return;
	}
	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;
	cout << '\n';
}

bool testcases = 0;
                  
signed main() {
#ifndef 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();
    }
}

Compilation message (stderr)

count_triplets.cpp: In function 'int main()':
count_triplets.cpp:100:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  100 |  freopen(".in", "r", stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~
count_triplets.cpp:101:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  101 |  freopen(".out", "w", stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
#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...