# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
290193 |
2020-09-03T13:21:48 Z |
SamAnd |
Simurgh (IOI17_simurgh) |
C++17 |
|
0 ms |
384 KB |
#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 (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)
| ~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
384 KB |
WA in grader: NO |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
384 KB |
WA in grader: NO |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
384 KB |
WA in grader: NO |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
correct |
2 |
Incorrect |
0 ms |
384 KB |
WA in grader: NO |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
384 KB |
WA in grader: NO |
2 |
Halted |
0 ms |
0 KB |
- |