이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
using ll = long long;
int lst[100005], to[200005], pre[200005], tot;
int low[100005], dfn[100005], st[100005], clk, tp;
int sz[200005], n, m, t_cnt;
std::vector<int> son[200005];
ll ans;
inline void add_edge(int u, int v)
{
to[tot] = v;
pre[tot] = lst[u];
lst[u] = tot++;
}
void tarjan(int u, int fa = -1)
{
dfn[u] = low[u] = clk++;
st[tp++] = u;
for (int i = lst[u]; ~i; i = pre[i])
{
int v = to[i];
if (-1 == dfn[v])
{
tarjan(v, i ^ 1);
low[u] = std::min(low[u], low[v]);
if (low[v] >= dfn[u])
{
son[u].push_back(t_cnt);
do
son[t_cnt].push_back(st[--tp]);
while (st[tp] != v);
t_cnt++;
}
}
else if (i != fa)
low[u] = std::min(low[u], dfn[v]);
}
}
void dfs(int u)
{
sz[u] = u < n;
for (int v : son[u])
{
dfs(v);
sz[u] += sz[v];
}
}
void work(int u, int rt, int fa = -1)
{
for (int v : son[u])
{
if (u < n)
ans += (ll)sz[v] * (sz[rt] - sz[v] - 1);
else
ans += (ll)sz[v] * (sz[rt] - sz[v]) * (son[u].size() - 1);
work(v, rt, u);
}
if (~fa)
{
if (u < n)
ans += (ll)(sz[rt] - sz[u]) * (sz[u] - 1);
else
ans += (ll)(sz[rt] - sz[u]) * sz[u] * (son[u].size() - 1);
}
}
int main()
{
// freopen("uoj-416.in", "r", stdin);
memset(lst, -1, sizeof(lst));
memset(dfn, -1, sizeof(dfn));
scanf("%d%d", &n, &m);
for (int i = 0; i < m; i++)
{
int u, v;
scanf("%d%d", &u, &v);
add_edge(--u, --v);
add_edge(v, u);
}
t_cnt = n;
for (int i = 0; i < n; i++)
{
if (-1 == dfn[i])
{
tarjan(i);
dfs(i);
work(i, i);
}
}
printf("%lld\n", ans);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
count_triplets.cpp: In function 'int main()':
count_triplets.cpp:73:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &n, &m);
~~~~~^~~~~~~~~~~~~~~~
count_triplets.cpp:77:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &u, &v);
~~~~~^~~~~~~~~~~~~~~~
# | 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... |