# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
135032 | 2019-07-23T14:39:56 Z | Lawliet | Duathlon (APIO18_duathlon) | C++14 | 1000 ms | 1048580 KB |
#include <bits/stdc++.h> #define MAX 100010 using namespace std; typedef long long int lli; int n, m; int n1, n2; int sub[MAX]; int prof[MAX]; lli ans; lli sumProf[MAX]; lli ansRoot[MAX]; bool marc[MAX]; vector<int> grafo[MAX]; void DFSCalculate(int i, int p, int depth) { sub[i] = 1; marc[i] = true; sumProf[i] = depth; for(int g = 0 ; g < grafo[i].size() ; g++) { int prox = grafo[i][g]; if(prox == p) continue; DFSCalculate(prox , i , depth + 1); sub[i] += sub[prox];//SOMA ATÉ RAIZ sumProf[i] += sumProf[prox]; } } void DFSRotate(int i, int p) { ansRoot[i] = sumProf[i]; for(int g = 0 ; g < grafo[i].size() ; g++) { int prox = grafo[i][g]; if(prox == p) continue; int lastSubI = sub[i]; int lastSubProx = sub[prox]; lli lastSumI = sumProf[i]; lli lastSumProx = sumProf[prox]; sub[i] -= sub[prox]; sumProf[i] -= sumProf[prox]; sumProf[prox] += sumProf[i] + sub[i] - sub[prox]; sub[prox] += sub[i]; DFSRotate(prox , i); sub[i] = lastSubI; sub[prox] = lastSubProx; sumProf[i] = lastSumI; sumProf[prox] = lastSumProx; } } int main() { scanf("%d %d",&n,&m); for(int g = 0 ; g < m ; g++) { scanf("%d %d",&n1,&n2); grafo[n1].push_back(n2); grafo[n2].push_back(n1); } for(int g = 1 ; g <= n ; g++) { if(marc[g]) continue; DFSCalculate(g , g , 0); DFSRotate(g , g); lli p = sub[g]; p *= sub[g] - 1; ans -= p; } for(int g = 1 ; g <= n ; g++) ans += ansRoot[g]; printf("%lld\n",ans); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 985 ms | 1048576 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 985 ms | 1048576 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 1105 ms | 344440 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 2680 KB | Output is correct |
2 | Correct | 4 ms | 2808 KB | Output is correct |
3 | Correct | 5 ms | 2808 KB | Output is correct |
4 | Correct | 5 ms | 2808 KB | Output is correct |
5 | Correct | 4 ms | 2808 KB | Output is correct |
6 | Correct | 4 ms | 2808 KB | Output is correct |
7 | Correct | 4 ms | 2808 KB | Output is correct |
8 | Correct | 4 ms | 2808 KB | Output is correct |
9 | Correct | 5 ms | 2808 KB | Output is correct |
10 | Correct | 4 ms | 2680 KB | Output is correct |
11 | Correct | 6 ms | 2808 KB | Output is correct |
12 | Correct | 5 ms | 2812 KB | Output is correct |
13 | Correct | 5 ms | 2680 KB | Output is correct |
14 | Correct | 4 ms | 2808 KB | Output is correct |
15 | Correct | 4 ms | 2808 KB | Output is correct |
16 | Correct | 4 ms | 2808 KB | Output is correct |
17 | Correct | 4 ms | 2680 KB | Output is correct |
18 | Correct | 4 ms | 2808 KB | Output is correct |
19 | Correct | 5 ms | 2780 KB | Output is correct |
20 | Correct | 5 ms | 2812 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 90 ms | 9208 KB | Output is correct |
2 | Correct | 121 ms | 9180 KB | Output is correct |
3 | Correct | 86 ms | 9272 KB | Output is correct |
4 | Correct | 84 ms | 9376 KB | Output is correct |
5 | Correct | 84 ms | 9304 KB | Output is correct |
6 | Correct | 111 ms | 14328 KB | Output is correct |
7 | Correct | 93 ms | 12536 KB | Output is correct |
8 | Correct | 91 ms | 11640 KB | Output is correct |
9 | Correct | 101 ms | 10952 KB | Output is correct |
10 | Correct | 84 ms | 9272 KB | Output is correct |
11 | Correct | 79 ms | 9208 KB | Output is correct |
12 | Correct | 76 ms | 9340 KB | Output is correct |
13 | Correct | 76 ms | 9208 KB | Output is correct |
14 | Correct | 76 ms | 8948 KB | Output is correct |
15 | Correct | 67 ms | 8772 KB | Output is correct |
16 | Correct | 40 ms | 7800 KB | Output is correct |
17 | Correct | 57 ms | 9580 KB | Output is correct |
18 | Correct | 56 ms | 9456 KB | Output is correct |
19 | Correct | 52 ms | 9456 KB | Output is correct |
20 | Correct | 53 ms | 9464 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 2684 KB | Output is correct |
2 | Correct | 4 ms | 2680 KB | Output is correct |
3 | Execution timed out | 1074 ms | 1048580 KB | Time limit exceeded |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 80 ms | 9252 KB | Output is correct |
2 | Correct | 88 ms | 9084 KB | Output is correct |
3 | Execution timed out | 1104 ms | 866148 KB | Time limit exceeded |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 985 ms | 1048576 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 985 ms | 1048576 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |