# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1118729 | Ntd123 | Duathlon (APIO18_duathlon) | C++14 | 1161 ms | 1048576 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define PB push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define bit(x, i) ((x >> i) & 1)
#define il (node * 2)
#define ir (il + 1)
#define mid (l + r)/2
#define maxn
#define ll long long
#define pii pair <int, int>
#define MOD 1000000007
#define Task "b2"
#define int long long
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N = 100005;
int n, m, d, cnt = 0, com = 0, ans = 0;
int luu[N], low[N], s[N];
stack <int> st;
vector <int> a[N], tree[N];
void DFS(int x, int y){
st.push(x);
d++;
luu[x] = low[x] = ++ cnt;
for (int i: a[x]){
if (i == y) continue;
if (luu[i]) low[x] = min(low[x], luu[i]);
else {
DFS(i, x);
low[x] = min(low[x], low[i]);
if (luu[x] <= low[i]){
com++;
tree[x].PB(com);
while (!tree[com].size() || tree[com].back() != i)
tree[com].PB(st.top()), st.pop();
}
}
}
}
void DFS1(int x){
s[x] = (x <= n);
for (int i: tree[x]){
DFS1(i);
s[x] += s[i];
if (i <= n) ans -= tree[x].size()*s[i]*(s[i]-1);
}
if (x > n) ans -= tree[x].size()*(d-s[x])*(d-s[x]-1);
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
if(fopen(Task".inp", "r")) {
freopen(Task".inp", "r", stdin);
freopen(Task".out", "w", stdout);
}
cin >> n >> m;
com = n;
for (int i = 1; i <= m; i ++){
int u, v;
cin >> u >> v;
a[u].PB(v);
a[v].PB(u);
}
for (int i = 1; i <= n; i ++)
if (!luu[i]){
d=0;
DFS(i, 0);
ans += d*(d-1)*(d-2);
DFS1(i);
}
cout << ans;
cerr << "\nTime elapsed: " << 1000.0 * clock() / CLOCKS_PER_SEC << " ms.\n";
return 0;
}
Compilation message (stderr)
# | 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... |