This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "simurgh.h"
#include <bits/stdc++.h>
using namespace std;
#define forn(i,n) for(int i=0;i<n;++i)
#define pb push_back
#define pi pair<int,int>
#define f first
#define s second
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rand(int a, int b) {return a+rng()%(b-a+1);}
#define all(x) x.begin(),x.end()
struct DSU {
vector<int> p,sz;
DSU(int n) {
forn(i,n) p.pb(i), sz.pb(1);
}
int get(int u) {
return p[u]==u?u:get(p[u]);
}
void uni(int u, int v) {
u=get(u), v=get(v);
if (u==v) return;
if (sz[u]<sz[v]) swap(u,v);
p[v]=u;
sz[u]+=sz[v];
}
};
vector<int> f(vector<int>&z) {
vector<int> v;
forn(i,z.size()) if (z[i]) v.pb(i);
return v;
}
int ask(vector<int>&z) {
auto v=f(z);
return count_common_roads(v);
}
vector<int> find_roads(int n, vector<int>u, vector<int>v) {
int m=u.size();
if (m==n-1) {
vector<int> v; forn(i,n) v.pb(i);
return v;
}
if (n>7) exit(0);
int l=1;
forn(j,n) l*=m-j;
forn(mask,1<<m) {
if (__builtin_popcount(mask)!=n-1) continue;
vector<int> z(m,0);
forn(i,m) if ((mask>>i)&1) z[i]=1;
DSU dsu(n);
forn(i,m) if (z[i]) dsu.uni(u[i],v[i]);
if (dsu.sz[dsu.get(0)]!=n) continue;
int x=ask(z);
if (x==n-1) return f(z);
next_permutation(all(z));
}
}
Compilation message (stderr)
simurgh.cpp: In function 'std::vector<int> first(std::vector<int>&)':
simurgh.cpp:4:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
4 | #define forn(i,n) for(int i=0;i<n;++i)
......
33 | forn(i,z.size()) if (z[i]) v.pb(i);
| ~~~~~~~~~~
simurgh.cpp:33:2: note: in expansion of macro 'forn'
33 | forn(i,z.size()) if (z[i]) v.pb(i);
| ^~~~
simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:61:1: warning: control reaches end of non-void function [-Wreturn-type]
61 | }
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |