# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
597790 | 2022-07-16T21:51:33 Z | ThegeekKnight16 | Paths (RMI21_paths) | C++17 | 1 ms | 736 KB |
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e3 + 10; int Dist[MAXN]; vector<int> folhas; vector<int> grafo[MAXN], pesos[MAXN]; vector<int> Marc[MAXN]; int pai[MAXN], indicesPai[MAXN]; void dfs(int v) { for (int i = 0; i < grafo[v].size(); i++) { int viz = grafo[v][i]; int p = pesos[v][i]; if (viz == pai[v]) continue; if (Marc[v][i]) p = 0; pai[viz] = v; indicesPai[viz] = i; Dist[viz] = Dist[v] + p; dfs(viz); } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int N, K; cin >> N >> K; for (int i = 1; i < N; i++) { int X, Y, P; cin >> X >> Y >> P; grafo[X].push_back(Y); pesos[X].push_back(P); grafo[Y].push_back(X); pesos[Y].push_back(P); Marc[X].push_back(0); Marc[Y].push_back(0); } for (int i = 1; i <= N; i++) if (grafo[i].size() == 1) folhas.push_back(i); int resp = 0; for (int v = 1; v <= N; v++) { resp = 0; //cerr << "v: " << v << '\n'; for (int k = 1; k <= K; k++) { Dist[v] = 0; pai[v] = v; dfs(v); int aux = -1; int auxF = 0; for (int folha : folhas) { if (folha == v) continue; if (Dist[folha] > aux) { aux = Dist[folha]; auxF = folha; } } resp += aux; while (auxF != v) { //cerr << auxF << " " << pai[auxF] << " " << indicesPai[auxF] << '\n'; Marc[pai[auxF]][indicesPai[auxF]] = 1; auxF = pai[auxF]; } //cerr << '\n'; } cout << resp << '\n'; for (int i = 1; i <= N; i++) { for (int j = 0; j < Marc[i].size(); j++) Marc[i][j] = 0; } } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 468 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 468 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 468 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 468 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 1 ms | 736 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 468 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |