이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <algorithm>
#include <array>
#include <deque>
#include <queue>
#include <map>
#define ll long long
using namespace std;
bool visited[100000];
ll n, m, a, b, g, cnt, sz, f, low[100000], st[100000], X[100000];
map <array<ll, 2>, ll> bridge;
vector <ll> G;
vector <array<ll, 2>> bg;
vector <ll> bcc, dp;
vector <ll> adj[100000], E[100000], badj[100000];
void tar(ll u, ll p) {
G.push_back(u);
st[u] = low[u] = ++cnt;
for (auto v : adj[u]) {
if (!st[v]) {
tar(v, u);
low[u] = min(low[u], low[v]);
if (low[v] > st[u]) {
++bridge[{u, v}];
}
}
else if (v != p) {
low[u] = min(low[u], st[v]);
}
}
}
void dfs(ll u) {
++sz;
X[u] = g;
visited[u] = 1;
for (auto v : E[u]) {
if (!visited[v]) {
dfs(v);
}
}
}
void calc(ll u, ll p) {
dp[u] = bcc[u];
for (auto v : badj[u]) {
if (v != p) {
calc(v, u);
dp[u] += dp[v];
}
}
}
void solve(ll u, ll p, ll w) {
ll s = 0;
for (auto v : badj[u]) {
if (v != p) {
s += dp[v];
}
}
f += w * s * 2;
w += s;
for (auto v : badj[u]) {
if (v != p) {
f += bcc[u] * dp[v] * (s-dp[v]);
solve(v, u, w-dp[v]+bcc[u]);
}
}
}
int main() {
cin >> n >> m;
for (int i=0; i<m; ++i) {
cin >> a >> b;
--a, --b;
adj[a].push_back(b);
adj[b].push_back(a);
X[i] = -1;
}
for (int i=0; i<n; ++i) {
if (!st[i]) {
G.clear();
bg.clear();
bcc.clear();
tar(i, -1);
for (auto u : G) {
for (auto v : adj[u]) {
if (bridge.find({u, v}) == bridge.end() && bridge.find({v, u}) == bridge.end()) {
E[u].push_back(v);
E[v].push_back(u);
}
else bg.push_back({u, v});
}
}
g = 0;
for (auto u : G) {
if (!visited[u]) {
sz = 0;
dfs(u);
++g;
if (sz >= 3) f += sz * (sz-1) * (sz-2);
bcc.push_back(sz);
}
}
for (auto sz : bcc) {
if (sz >= 2) f += (sz-1) * (sz-1) * ((ll)G.size() - sz) * 2;
}
dp.resize(bcc.size());
for (auto [x, y] : bg) {
badj[X[x]].push_back({X[y]});
}
calc(0, -1);
solve(0, -1, 0);
for (int i=0; i<g; ++i) badj[i].clear();
}
}
cout << f << '\n';
}
컴파일 시 표준 에러 (stderr) 메시지
count_triplets.cpp: In function 'int main()':
count_triplets.cpp:113:17: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
113 | for (auto [x, y] : bg) {
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |