# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
235192 | Vimmer | Usmjeri (COCI17_usmjeri) | C++14 | 450 ms | 37036 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>
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("no-stack-protector")
#define F first
#define S second
#define sz(x) int(x.size())
#define pb push_back
#define N 300001
#define M ll(1e9 + 7)
#define inf 1e9 + 1e9
using namespace std;
typedef long double ld;
typedef long long ll;
typedef short int si;
vector <int> g[N], a[N];
int main()
{
// freopen("input.txt", "r", stdin); //freopen("output4.txt", "w", stdout);
ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n, m;
cin >> n >> m;
for (int i = 1; i < n; i++)
{
int x, y;
cin >> x >> y;
g[x].pb(y);
g[y].pb(x);
}
int beg;
for (int i = 1; i <= n; i++) if (sz(g[i]) == 1) beg = i;
for (; m > 0 ; m--)
{
int x, y;
cin >> x >> y;
a[x].pb(m);
a[y].pb(m);
}
vector <int> vr; vr.clear();
int v = beg, p = -1;
while (v != -1)
{
int nxt = -1;
vr.pb(v);
for (auto it : g[v])
{
if (it == p) continue;
nxt = it;
}
p = v;
v = nxt;
}
ll ans = 1;
set <int> se; se.clear();
for (int i = 0; i < sz(vr); i++)
{
int v = vr[i];
bool f = 1;
if (i != 0 && sz(se) == 0) {f = 0; ans = (ans + ans) % M;}
for (auto it : a[vr[i]])
{
if (se.find(it) == se.end()) se.insert(it);
else se.erase(it);
}
if (i != 0 && f && sz(se) == 0) ans = (ans + ans) % M;
}
cout << ans << endl;
}
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... |
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |