# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1079091 |
2024-08-28T10:37:21 Z |
Gray |
Simurgh (IOI17_simurgh) |
C++17 |
|
64 ms |
3900 KB |
#include "simurgh.h"
#include <bits/stdc++.h>
using namespace std;
#define ll int
#define ff first
#define ss second
#define ln "\n"
#define ld long double
vector<pair<ll, ll>> e;
vector<vector<ll>> A;
// Slow version
vector<ll> checka;
void dfs(ll u, vector<bool> &vis, ll mask){
vis[u]=1;
for (auto i:A[u]){
if (mask&(1<<i)){
ll v = e[i].ff^e[i].ss^u;
if (vis[v]) continue;
dfs(v, vis, mask);
}
}
}
bool check(ll mask, ll n, ll m){
checka.clear();
vector<bool> vis(n);
dfs(0, vis, mask);
for (ll i=0; i<n; i++) if (!vis[i]) return 0;
for (ll i=0; i<m; i++){
if (mask&(1<<i)) checka.push_back(i);
}
return 1;
}
vector<int> find_roads_slow(int _n, vector<int> u, vector<int> v) {
int n=_n, m=u.size();
e.resize(m); A.clear(); A.resize(n);
for (ll i=0; i<m; i++){
e[i]={u[i], v[i]};
A[u[i]].push_back(i); A[v[i]].push_back(i);
}
vector<ll> ans;
for (ll i=0; i<(1ll<<m); i++){
if (__builtin_popcount(i)==n-1){
if (check(i, n, m)) {
ll ret = count_common_roads(checka);
if (ret==n-1){
ans=checka; break;
}
}
}
}
return ans;
}
ll n, m;
vector<bool> isBridge;
void findBridge(ll u, ll p, vector<ll> &tin, vector<ll> &tmin, ll &timer){
tin[u]=tmin[u]=timer++;
for (auto i:A[u]){
ll v = e[i].ff^e[i].ss^u;
if (v==p) continue;
if (tin[v]==-1) findBridge(v, u, tin, tmin, timer);
tmin[u]=min(tmin[u], tmin[v]);
if (tin[u]<tmin[v]){
isBridge[i]=1;
}
}
}
vector<bool> noroyal;
void findST(ll u, vector<bool> &vis, vector<ll> &edges){
vis[u]=1;
for (auto i:A[u]){
if (noroyal[i]) continue;
ll v = e[i].ff^e[i].ss^u;
if (vis[v]) continue;
edges.push_back(i);
findST(v, vis, edges);
}
}
struct DSU{
vector<ll> p;
ll sz;
DSU(ll N){
sz=N;
p.resize(N+1, -1);
}
ll get(ll x){
return (p[x]==-1?x:p[x]=get(p[x]));
}
bool unite(ll u, ll v){
u=get(u); v=get(v);
if (u==v) return 0;
p[u]=v;
return 1;
}
};
ll check(vector<ll> incl, ll excl){
DSU tr(n);
vector<ll> checkarr;
for (auto i:incl){
if (i==excl) continue;
checkarr.push_back(i);
tr.unite(e[i].ff, e[i].ss);
}
ll ret=INT_MAX;
for (ll i=0; i<m; i++){
if (i==excl) continue;
if (tr.get(e[i].ff)!=tr.get(e[i].ss)){
checkarr.push_back(i);
ret=min(ret, count_common_roads(checkarr));
checkarr.pop_back();
}
}
// cout << "IDRequest: " << excl << ": " << ret << ln;
// for (auto ch:checkarr) cout << ch << " ";
// cout << ":: ";
// ll ret=count_common_roads(checkarr);
// cout << ret << ln;
return ret;
}
vector<int> find_roads(int _n, vector<int> u, vector<int> v) {
n=_n; m=u.size();
e.resize(m); A.clear(); A.resize(n);
for (ll i=0; i<m; i++){
e[i]={u[i], v[i]};
A[u[i]].push_back(i); A[v[i]].push_back(i);
}
isBridge.clear(); isBridge.resize(m);
vector<ll> tin(n, -1), tmin(n, -1); ll timer=0;
findBridge(0, 0, tin, tmin, timer);
noroyal.clear(); noroyal.resize(m, 0);
vector<ll> ans;
vector<bool> vis(n); vector<ll> edges;
// for (ll i=0; i<m; i++) cout << isBridge[i] << " ";
// cout << ln; return ans;
while (ans.size()==0){
edges.clear(); vis.assign(n, 0);
findST(0, vis, edges);
// cout << "Request: ";
// for (auto ch:edges) cout << ch << " ";
// cout << ":: ";
ll ret = count_common_roads(edges);
// cout << ret << ln;
if (ret==n-1){
ans=edges; break;
}
for (auto i:edges){
if (isBridge[i]) continue;
ll nret=check(edges, i);
if (nret>=ret){
noroyal[i]=1;
}
}
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
correct |
2 |
Correct |
0 ms |
344 KB |
correct |
3 |
Correct |
0 ms |
348 KB |
correct |
4 |
Correct |
0 ms |
348 KB |
correct |
5 |
Correct |
0 ms |
348 KB |
correct |
6 |
Incorrect |
0 ms |
348 KB |
WA in grader: NO |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
correct |
2 |
Correct |
0 ms |
344 KB |
correct |
3 |
Correct |
0 ms |
348 KB |
correct |
4 |
Correct |
0 ms |
348 KB |
correct |
5 |
Correct |
0 ms |
348 KB |
correct |
6 |
Incorrect |
0 ms |
348 KB |
WA in grader: NO |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
correct |
2 |
Correct |
0 ms |
344 KB |
correct |
3 |
Correct |
0 ms |
348 KB |
correct |
4 |
Correct |
0 ms |
348 KB |
correct |
5 |
Correct |
0 ms |
348 KB |
correct |
6 |
Incorrect |
0 ms |
348 KB |
WA in grader: NO |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
correct |
2 |
Correct |
0 ms |
348 KB |
correct |
3 |
Incorrect |
64 ms |
3900 KB |
WA in grader: NO |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
correct |
2 |
Correct |
0 ms |
344 KB |
correct |
3 |
Correct |
0 ms |
348 KB |
correct |
4 |
Correct |
0 ms |
348 KB |
correct |
5 |
Correct |
0 ms |
348 KB |
correct |
6 |
Incorrect |
0 ms |
348 KB |
WA in grader: NO |
7 |
Halted |
0 ms |
0 KB |
- |