| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 643211 | danikoynov | Paths (RMI21_paths) | C++14 | 1085 ms | 18796 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 10;
int n, k, par[maxn], rev_idx[maxn];
ll depth[maxn];
vector < pair < int, ll > > g[maxn], sg[maxn];
void trav(int v, int p)
{
par[v] = p;
for (int i = 0; i < g[v].size(); i ++)
{
pair < int, ll > nb = g[v][i];
if (nb.first == p)
continue;
rev_idx[nb.first] = i;
trav(nb.first, v);
}
}
void calc(int v)
{
for (int i = 0; i < g[v].size(); i++)
{
pair < int, ll > nb = g[v][i];
if (nb.first == par[v])
continue;
depth[nb.first] = depth[v] + nb.second;
calc(nb.first);
}
}
int fver;
void clean(int v)
{
while(v != fver)
{
g[par[v]][rev_idx[v]].second = 0;
v = par[v];
}
}
void solve()
{
cin >> n >> k;
for (int i = 1; i < n; i ++)
{
int v, u;
ll l;
cin >> v >> u >> l;
g[v].push_back({u, l});
sg[v].push_back({u, l});
g[u].push_back({v, l});
sg[u].push_back({v, l});
}
for (int ver = 1; ver <= n; ver ++)
{
fver = ver;
for (int i = 1; i <= n; i ++)
g[i] = sg[i];
trav(ver, -1);
ll ans = 0;
for (int i = 1; i <= k; i ++)
{
depth[ver] = 0;
calc(ver);
int mx = 1;
for (int j = 2; j <= n; j ++)
if (depth[j] > depth[mx])
mx = j;
ans = ans + depth[mx];
clean(mx);
}
cout << ans << endl;
}
}
int main()
{
solve();
return 0;
}
컴파일 시 표준 에러 (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... | ||||
