# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
49639 | 2018-06-01T14:01:56 Z | gs13105 | Duathlon (APIO18_duathlon) | C++17 | 1000 ms | 1048576 KB |
#include <cstdio> #include <cstdlib> #include <cstring> #include <cassert> #include <iostream> #include <algorithm> #include <string> #include <vector> #include <list> #include <stack> #include <queue> #include <deque> #include <set> #include <map> #include <tuple> #include <iterator> using namespace std; const int MAXN = 100000; vector<int> arr[MAXN + 10]; int dis[MAXN + 10]; int low[MAXN + 10]; int tim; vector<int> bcc[MAXN + 10]; vector<int> cmp[MAXN + 10]; int siz; int cur; void f(int x, int p) { cur++; dis[x] = ++tim; low[x] = dis[x]; for(int &y : arr[x]) { if(y == p) continue; if(!dis[y]) { f(y, x); low[x] = min(low[x], low[y]); } else low[x] = min(low[x], dis[y]); } } void color(int x, int c) { if(c) { bcc[c].push_back(x); cmp[x].push_back(c); } for(auto &i : arr[x]) { if(cmp[i].size()) continue; if(low[i] >= dis[x]) { bcc[++siz].push_back(x); cmp[x].push_back(siz); color(i, siz); } else color(i, c); } } int cnt[MAXN + 10]; long long g(int c, int p) { long long r = 0; long long t = 0; for(int x : bcc[c]) { int sum = 1; for(int d : cmp[x]) { if(d == c || d == p) continue; r += g(d, c); sum += cnt[d] - 1; } cnt[c] += sum; t += 1LL * sum * (sum - 1); } int tmp = cur - cnt[c] + 1; t += 1LL * tmp * (tmp - 1); r += ((int)bcc[c].size() - 1) * t; return r; } int main() { //freopen("in", "r", stdin); //freopen("out", "w", stdout); int n, m, i; scanf("%d%d", &n, &m); for(i = 0; i < m; i++) { int x, y; scanf("%d%d", &x, &y); arr[x].push_back(y); arr[y].push_back(x); } long long r = 0; for(i = 1; i <= n; i++) { if(dis[i]) continue; cur = 0; f(i, 0); color(i, 0); if(cur < 3) continue; long long t = g(siz, 0); int sz = cur; r += 1LL * sz * (sz - 1) * (sz - 2) - t; } printf("%lld", r); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 7288 KB | Output is correct |
2 | Correct | 8 ms | 7524 KB | Output is correct |
3 | Correct | 8 ms | 7524 KB | Output is correct |
4 | Correct | 7 ms | 7548 KB | Output is correct |
5 | Correct | 8 ms | 7624 KB | Output is correct |
6 | Correct | 7 ms | 7628 KB | Output is correct |
7 | Execution timed out | 1090 ms | 1021788 KB | Time limit exceeded |
8 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 7288 KB | Output is correct |
2 | Correct | 8 ms | 7524 KB | Output is correct |
3 | Correct | 8 ms | 7524 KB | Output is correct |
4 | Correct | 7 ms | 7548 KB | Output is correct |
5 | Correct | 8 ms | 7624 KB | Output is correct |
6 | Correct | 7 ms | 7628 KB | Output is correct |
7 | Execution timed out | 1090 ms | 1021788 KB | Time limit exceeded |
8 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 183 ms | 1021788 KB | Output is correct |
2 | Correct | 162 ms | 1021788 KB | Output is correct |
3 | Correct | 212 ms | 1021788 KB | Output is correct |
4 | Correct | 199 ms | 1021788 KB | Output is correct |
5 | Correct | 187 ms | 1021788 KB | Output is correct |
6 | Correct | 195 ms | 1021788 KB | Output is correct |
7 | Correct | 190 ms | 1021788 KB | Output is correct |
8 | Correct | 195 ms | 1021788 KB | Output is correct |
9 | Correct | 246 ms | 1021788 KB | Output is correct |
10 | Correct | 211 ms | 1021788 KB | Output is correct |
11 | Correct | 122 ms | 1021788 KB | Output is correct |
12 | Correct | 122 ms | 1021788 KB | Output is correct |
13 | Correct | 114 ms | 1021788 KB | Output is correct |
14 | Correct | 117 ms | 1021788 KB | Output is correct |
15 | Correct | 89 ms | 1021788 KB | Output is correct |
16 | Correct | 92 ms | 1021788 KB | Output is correct |
17 | Correct | 11 ms | 1021788 KB | Output is correct |
18 | Correct | 11 ms | 1021788 KB | Output is correct |
19 | Correct | 12 ms | 1021788 KB | Output is correct |
20 | Correct | 11 ms | 1021788 KB | Output is correct |
21 | Correct | 10 ms | 1021788 KB | Output is correct |
22 | Correct | 10 ms | 1021788 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 1094 ms | 1048576 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 1187 ms | 1048576 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 1096 ms | 1048576 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 1143 ms | 1048576 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 7288 KB | Output is correct |
2 | Correct | 8 ms | 7524 KB | Output is correct |
3 | Correct | 8 ms | 7524 KB | Output is correct |
4 | Correct | 7 ms | 7548 KB | Output is correct |
5 | Correct | 8 ms | 7624 KB | Output is correct |
6 | Correct | 7 ms | 7628 KB | Output is correct |
7 | Execution timed out | 1090 ms | 1021788 KB | Time limit exceeded |
8 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 7288 KB | Output is correct |
2 | Correct | 8 ms | 7524 KB | Output is correct |
3 | Correct | 8 ms | 7524 KB | Output is correct |
4 | Correct | 7 ms | 7548 KB | Output is correct |
5 | Correct | 8 ms | 7624 KB | Output is correct |
6 | Correct | 7 ms | 7628 KB | Output is correct |
7 | Execution timed out | 1090 ms | 1021788 KB | Time limit exceeded |
8 | Halted | 0 ms | 0 KB | - |