#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;
if (h == p)
continue;
v.push_back(t[x][i].se);
if (dfs(h, x, y))
return true;
v.pop_back();
}
return false;
}
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(0);
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 (yans > ans)
{
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]));
}
}
break;
}
}
while (1){}
}
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)
| ~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
correct |
2 |
Correct |
1 ms |
384 KB |
correct |
3 |
Correct |
1 ms |
384 KB |
correct |
4 |
Correct |
1 ms |
384 KB |
correct |
5 |
Correct |
1 ms |
384 KB |
correct |
6 |
Correct |
1 ms |
384 KB |
correct |
7 |
Correct |
0 ms |
384 KB |
correct |
8 |
Correct |
1 ms |
384 KB |
correct |
9 |
Correct |
0 ms |
384 KB |
correct |
10 |
Correct |
1 ms |
384 KB |
correct |
11 |
Correct |
1 ms |
384 KB |
correct |
12 |
Correct |
1 ms |
384 KB |
correct |
13 |
Correct |
1 ms |
384 KB |
correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
correct |
2 |
Correct |
1 ms |
384 KB |
correct |
3 |
Correct |
1 ms |
384 KB |
correct |
4 |
Correct |
1 ms |
384 KB |
correct |
5 |
Correct |
1 ms |
384 KB |
correct |
6 |
Correct |
1 ms |
384 KB |
correct |
7 |
Correct |
0 ms |
384 KB |
correct |
8 |
Correct |
1 ms |
384 KB |
correct |
9 |
Correct |
0 ms |
384 KB |
correct |
10 |
Correct |
1 ms |
384 KB |
correct |
11 |
Correct |
1 ms |
384 KB |
correct |
12 |
Correct |
1 ms |
384 KB |
correct |
13 |
Correct |
1 ms |
384 KB |
correct |
14 |
Correct |
6 ms |
512 KB |
correct |
15 |
Correct |
6 ms |
512 KB |
correct |
16 |
Correct |
6 ms |
512 KB |
correct |
17 |
Correct |
5 ms |
516 KB |
correct |
18 |
Correct |
2 ms |
512 KB |
correct |
19 |
Correct |
4 ms |
512 KB |
correct |
20 |
Correct |
4 ms |
512 KB |
correct |
21 |
Correct |
5 ms |
512 KB |
correct |
22 |
Correct |
1 ms |
512 KB |
correct |
23 |
Correct |
1 ms |
512 KB |
correct |
24 |
Correct |
1 ms |
384 KB |
correct |
25 |
Correct |
1 ms |
384 KB |
correct |
26 |
Correct |
1 ms |
384 KB |
correct |
27 |
Correct |
2 ms |
384 KB |
correct |
28 |
Correct |
1 ms |
384 KB |
correct |
29 |
Correct |
1 ms |
384 KB |
correct |
30 |
Correct |
1 ms |
384 KB |
correct |
31 |
Correct |
1 ms |
384 KB |
correct |
32 |
Correct |
1 ms |
384 KB |
correct |
33 |
Correct |
1 ms |
384 KB |
correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
correct |
2 |
Correct |
1 ms |
384 KB |
correct |
3 |
Correct |
1 ms |
384 KB |
correct |
4 |
Correct |
1 ms |
384 KB |
correct |
5 |
Correct |
1 ms |
384 KB |
correct |
6 |
Correct |
1 ms |
384 KB |
correct |
7 |
Correct |
0 ms |
384 KB |
correct |
8 |
Correct |
1 ms |
384 KB |
correct |
9 |
Correct |
0 ms |
384 KB |
correct |
10 |
Correct |
1 ms |
384 KB |
correct |
11 |
Correct |
1 ms |
384 KB |
correct |
12 |
Correct |
1 ms |
384 KB |
correct |
13 |
Correct |
1 ms |
384 KB |
correct |
14 |
Correct |
6 ms |
512 KB |
correct |
15 |
Correct |
6 ms |
512 KB |
correct |
16 |
Correct |
6 ms |
512 KB |
correct |
17 |
Correct |
5 ms |
516 KB |
correct |
18 |
Correct |
2 ms |
512 KB |
correct |
19 |
Correct |
4 ms |
512 KB |
correct |
20 |
Correct |
4 ms |
512 KB |
correct |
21 |
Correct |
5 ms |
512 KB |
correct |
22 |
Correct |
1 ms |
512 KB |
correct |
23 |
Correct |
1 ms |
512 KB |
correct |
24 |
Correct |
1 ms |
384 KB |
correct |
25 |
Correct |
1 ms |
384 KB |
correct |
26 |
Correct |
1 ms |
384 KB |
correct |
27 |
Correct |
2 ms |
384 KB |
correct |
28 |
Correct |
1 ms |
384 KB |
correct |
29 |
Correct |
1 ms |
384 KB |
correct |
30 |
Correct |
1 ms |
384 KB |
correct |
31 |
Correct |
1 ms |
384 KB |
correct |
32 |
Correct |
1 ms |
384 KB |
correct |
33 |
Correct |
1 ms |
384 KB |
correct |
34 |
Incorrect |
225 ms |
1540 KB |
WA in grader: NO |
35 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
correct |
2 |
Correct |
1 ms |
384 KB |
correct |
3 |
Incorrect |
170 ms |
3088 KB |
WA in grader: NO |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
correct |
2 |
Correct |
1 ms |
384 KB |
correct |
3 |
Correct |
1 ms |
384 KB |
correct |
4 |
Correct |
1 ms |
384 KB |
correct |
5 |
Correct |
1 ms |
384 KB |
correct |
6 |
Correct |
1 ms |
384 KB |
correct |
7 |
Correct |
0 ms |
384 KB |
correct |
8 |
Correct |
1 ms |
384 KB |
correct |
9 |
Correct |
0 ms |
384 KB |
correct |
10 |
Correct |
1 ms |
384 KB |
correct |
11 |
Correct |
1 ms |
384 KB |
correct |
12 |
Correct |
1 ms |
384 KB |
correct |
13 |
Correct |
1 ms |
384 KB |
correct |
14 |
Correct |
6 ms |
512 KB |
correct |
15 |
Correct |
6 ms |
512 KB |
correct |
16 |
Correct |
6 ms |
512 KB |
correct |
17 |
Correct |
5 ms |
516 KB |
correct |
18 |
Correct |
2 ms |
512 KB |
correct |
19 |
Correct |
4 ms |
512 KB |
correct |
20 |
Correct |
4 ms |
512 KB |
correct |
21 |
Correct |
5 ms |
512 KB |
correct |
22 |
Correct |
1 ms |
512 KB |
correct |
23 |
Correct |
1 ms |
512 KB |
correct |
24 |
Correct |
1 ms |
384 KB |
correct |
25 |
Correct |
1 ms |
384 KB |
correct |
26 |
Correct |
1 ms |
384 KB |
correct |
27 |
Correct |
2 ms |
384 KB |
correct |
28 |
Correct |
1 ms |
384 KB |
correct |
29 |
Correct |
1 ms |
384 KB |
correct |
30 |
Correct |
1 ms |
384 KB |
correct |
31 |
Correct |
1 ms |
384 KB |
correct |
32 |
Correct |
1 ms |
384 KB |
correct |
33 |
Correct |
1 ms |
384 KB |
correct |
34 |
Incorrect |
225 ms |
1540 KB |
WA in grader: NO |
35 |
Halted |
0 ms |
0 KB |
- |