# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
293101 |
2020-09-07T16:21:28 Z |
Saboon |
Simurgh (IOI17_simurgh) |
C++17 |
|
5 ms |
2816 KB |
#include "simurgh.h"
#include <bits/stdc++.h>
using namespace std;
const int maxn = 500 + 10;
vector<pair<int,int>> g[maxn];
int par[maxn], parindex[maxn], h[maxn];
bool visited[maxn];
int Cost, c[maxn*maxn];
void dfs(int v){
visited[v] = 1;
for (auto [u,idx] : g[v]){
if (!visited[u]){
h[u] = h[v]+1;
par[u] = v;
parindex[u] = idx;
dfs(u);
}
}
}
bool eq[maxn];
vector<int> Q;
vector<int> Dw[maxn];
vector<int> Ed[maxn];
int sz[maxn];
void solve(int l, int r, int x){
if (l >= r)
return;
int AllZero = Cost;
for (int i = l; i < r; i++){
Q[Dw[x][i]-1] = Ed[x][i];
AllZero -= c[parindex[Dw[x][i]]];
}
int Tmp = count_common_roads(Q);
if (Tmp != AllZero){
if (l+1 == r){
c[Ed[x][l]] = 1;
for (int i = l; i < r; i++)
Q[Dw[x][i]-1] = parindex[Dw[x][i]];
return;
}
int mid = (l+r)>>1;
solve(l,mid,x);
solve(mid,r,x);
}
for (int i = l; i < r; i++)
Q[Dw[x][i]-1] = parindex[Dw[x][i]];
}
vector<int> find_roads(int n, vector<int> u, vector<int> v){
int m = v.size();
for (int i = 0; i < v.size(); i++){
g[v[i]].push_back({u[i],i});
g[u[i]].push_back({v[i],i});
}
dfs(0);
Q.resize(n-1);
for (int i = 1; i < n; i++)
Q[i-1] = parindex[i];
Cost = count_common_roads(Q);
memset(c, -1, sizeof c);
for (int i = 0; i < m; i++){
if (h[v[i]] > h[u[i]])
swap(v[i],u[i]);
if (par[u[i]] == v[i])
continue;
int x = u[i], found = 0, me = -1;
while (x != v[i]){
if (c[parindex[x]] == -1)
found = 1;
x = par[x];
}
if (!found)
continue;
x = u[i];
while (x != v[i]){
if (c[parindex[x]] != -1 and me != -1){
x = par[x];
continue;
}
Q[x-1] = i;
int Tmp = count_common_roads(Q);
if (c[parindex[x]] != -1){
if (Tmp == Cost)
me = c[parindex[x]];
else
me = 1-c[parindex[x]];
}
else{
if (Tmp == Cost)
eq[x] = 1;
else if (Tmp > Cost)
eq[x] = 0, me = 1;
else
eq[x] = 0, me = 0;
}
Q[x-1] = parindex[x];
x = par[x];
}
if (me == -1)
me = 0;
x = u[i];
while (x != v[i]){
if (c[parindex[x]] == -1){
if (eq[x])
c[parindex[x]] = me;
else
c[parindex[x]] = 1-me;
}
x = par[x];
}
c[i] = me;
}
for (int i = 1; i < n; i++)
c[parindex[i]] = abs(c[parindex[i]]);
for (int i = 0; i < m; i++){
if (c[i] != -1)
continue;
Dw[sz[u[i]]].push_back(u[i]);
Ed[sz[u[i]]].push_back(i);
sz[u[i]] ++;
}
for (int i = 0; i < n; i++)
solve(0, Dw[i].size(), i);
int now = 0;
for (int i = 0; i < m; i++)
if (c[i] == 1)
Q[now++] = i;
return Q;
}
Compilation message
simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:56:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
56 | for (int i = 0; i < v.size(); i++){
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
1408 KB |
WA in grader: NO |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
1408 KB |
WA in grader: NO |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
1408 KB |
WA in grader: NO |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1408 KB |
correct |
2 |
Runtime error |
5 ms |
2816 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
1408 KB |
WA in grader: NO |
2 |
Halted |
0 ms |
0 KB |
- |