# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
955448 | yoav_s | Newspapers (CEOI21_newspapers) | C++17 | 475 ms | 279492 KiB |
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 <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<v> vv;
typedef vector<vv> vvv;
typedef pair<ll,ll> p;
typedef vector<p> vp;
typedef vector<vp> vvp;
typedef vector<vvp> vvvp;
typedef pair<ll, p> tri;
typedef vector<tri> vtri;
typedef vector<vtri> vvtri;
typedef vector<vvtri> vvvtri;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<vvb> vvvb;
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
const ll INF = 1e18;
const ll mod = 1e9 + 7;
int main()
{
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
ll N, M;
cin >> N >> M;
vv graph(N);
for (ll i= 0; i < M; i++)
{
ll a, b;
cin >> a >> b;
graph[a-1].pb(b-1);
graph[b-1].pb(a-1);
}
v next((1ll << N));
for (ll i= 0; i < (1ll << N); i++)
{
for (ll j = 0; j < N; j++)
{
if (i & (1 << j))
{
for (ll x : graph[j]) next[i] |= (1 << x);
}
}
}
vvp stateGraph((1ll << N));
for (ll i = 0; i < (1 << N); i++)
{
for (ll j = 0; j < N; j++)
{
if (i & (1 << j))
stateGraph[i].eb(next[i ^ (1 << j)], j);
}
}
vb visited((1 << N), false);
ll start = (1 << N) - 1; ll end = 0;
stack<ll> dfs;
dfs.push(start);
while (!dfs.empty())
{
auto top = dfs.top(); dfs.pop();
if (visited[top]) continue; visited[top] = true;
for (auto x : stateGraph[top]) dfs.push(x.f);
}
if (visited[end]) cout << "YES\n1\n1\n";
else cout << "NO\n";
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |