| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1067895 | Plurm | Torrent (COI16_torrent) | C++11 | 137 ms | 24992 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
vector<int> g[300005];
int dep[300005];
int chcnt[300005];
int col[300005];
int dp[300005];
int dfs(int u, int p = -1) {
vector<int> vec;
for (int v : g[u]) {
if (v == p)
continue;
dfs(v, u);
vec.push_back(dp[v]);
}
sort(vec.begin(), vec.end());
reverse(vec.begin(), vec.end());
for (int i = 0; i < vec.size(); i++) {
dp[u] = max(dp[u], vec[i] + i + 1);
}
return dp[u];
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, a, b;
cin >> n >> a >> b;
for (int i = 1; i < n; i++) {
int x, y;
cin >> x >> y;
g[x].push_back(y);
g[y].push_back(x);
}
memset(dep, 0x3f, sizeof(dep));
dep[a] = dep[b] = 0;
col[a] = 0;
col[b] = 1;
queue<int> q;
q.push(a);
q.push(b);
while (!q.empty()) {
int u = q.front();
q.pop();
for (int v : g[u]) {
if (dep[v] > dep[u] + 1) {
dep[v] = dep[u] + 1;
q.push(v);
col[v] = col[u];
}
}
}
for (int i = 1; i <= n; i++) {
for (int j : g[i]) {
if (col[j] != col[i]) {
g[i].erase(find(g[i].begin(), g[i].end(), j));
break;
}
}
}
cout << max({1, dfs(a), dfs(b)}) << endl;
return 0;
}컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
