#include "simurgh.h"
#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
typedef long long ll;
const int N = 503;
int n, m;
int g[N][N];
vector<pair<int, int> > t[N];
bool c[N];
vector<int> r;
void dfs0(int x)
{
c[x] = true;
for (int h = 0; h < n; ++h)
{
if (!g[x][h])
continue;
if (c[h])
continue;
t[x].push_back(m_p(h, g[x][h] - 1));
t[h].push_back(m_p(x, g[x][h] - 1));
r.push_back(g[x][h] - 1);
dfs0(h);
}
}
vector<int> v;
bool dfs(int x, int p, int y)
{
if (x == y)
return true;
for (int i = 0; i < t[x].size(); ++i)
{
int h = t[x][i].fi;
v.push_back(t[x][i].se);
if (dfs(h, x, y))
return true;
v.pop_back();
}
}
std::vector<int> find_roads(int n_, std::vector<int> u_, std::vector<int> v_)
{
n = n_;
m = sz(u_);
for (int i = 0; i < m; ++i)
{
int x = u_[i];
int y = v_[i];
g[x][y] = i + 1;
g[y][x] = i + 1;
}
dfs0(1);
int ans = count_common_roads(r);
if (ans == n - 1)
return r;
for (int i = 0; i < m; ++i)
{
int x = u_[i];
int y = v_[i];
v.clear();
dfs(x, x, y);
if (sz(v) == 1)
continue;
for (int j = 0; j < sz(v); ++j)
{
vector<int> yr;
for (int i = 0; i < n - 1; ++i)
{
if (r[i] == v[j])
continue;
yr.push_back(r[i]);
}
yr.push_back(i);
int yans = count_common_roads(yr);
if (ans == yans)
continue;
if (ans < yans)
{
r = yr;
ans = yans;
if (ans == n - 1)
return r;
for (int x = 0; x < n; ++x)
{
t[x].clear();
}
for (int i = 0; i < n - 1; ++i)
{
int x = u_[r[i]];
int y = v_[r[i]];
t[x].push_back(m_p(y, r[i]));
t[y].push_back(m_p(x, r[i]));
}
}
}
}
assert(false);
}
Compilation message
simurgh.cpp: In function 'bool dfs(int, int, int)':
simurgh.cpp:40:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
40 | for (int i = 0; i < t[x].size(); ++i)
| ~~^~~~~~~~~~~~~
simurgh.cpp:48:1: warning: control reaches end of non-void function [-Wreturn-type]
48 | }
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1479 ms |
1048580 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1479 ms |
1048580 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1479 ms |
1048580 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
correct |
2 |
Runtime error |
1457 ms |
1048580 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1479 ms |
1048580 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |