| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 855485 | Alfraganus | Hard route (IZhO17_road) | C++17 | 2058 ms | 860 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
#define fs first
#define ss second
#define all(a) a.begin(), a.end()
#define print(a) \
for (auto x : a) \
cout << x << ' '; \
cout << endl;
#define printmp(a) \
for (auto x : a) \
cout << x.fs << ' ' << x.ss << endl;
vector<vector<int>> graph;
vector<int> termials, path;
vector<bool> used;
queue<pair<int, int>> q;
bool dfs1(int node, int target){
if(node == target)
return true;
for(auto neighbour : graph[node]){
if(!used[neighbour]){
used[neighbour] = 1;
if(dfs1(neighbour, target)){
q.push({neighbour, 0});
path.push_back(neighbour);
return true;
}
}
}
return false;
}
void solve()
{
int n;
cin >> n;
graph.resize(n + 1);
used.resize(n + 1);
for(int i = 0; i < n - 1; i ++){
int a, b;
cin >> a >> b;
graph[a].push_back(b);
graph[b].push_back(a);
}
for(int i = 1; i <= n; i ++)
if(graph[i].size() == 1)
termials.push_back(i);
int ans1 = 0, ans2 = 0;
for(int i = 0; i < termials.size(); i ++){
for(int j = i + 1; j < termials.size(); j ++){
used.clear();
used.resize(n + 1);
path.clear();
path.push_back(termials[i]);
q.push({termials[i], 0});
dfs1(termials[i], termials[j]);
used.clear();
used.resize(n + 1);
for (auto x : path)
used[x] = 1;
int mx = 0;
while (!q.empty())
{
pair<int, int> x = q.front();
q.pop();
mx = max(mx, x.ss);
for (auto neighbour : graph[x.fs])
{
if (!used[neighbour])
{
used[neighbour] = 1;
q.push({neighbour, x.ss + 1});
}
}
}
if (ans1 < (path.size() - 1) * mx)
ans1 = (path.size() - 1) * mx, ans2 = 1;
else if (ans1 == (path.size() - 1) * mx)
ans2++;
}
}
cout << ans1 << ' ' << ans2 << endl;
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int t = 1;
// cin >> t;
while (t--)
{
solve();
cout << endl;
}
}컴파일 시 표준 에러 (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... | ||||
