Submission #235192

# Submission time Handle Problem Language Result Execution time Memory
235192 2020-05-27T09:44:39 Z Vimmer Usmjeri (COCI17_usmjeri) C++14
28 / 140
450 ms 37036 KB
#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

usmjeri.cpp: In function 'int main()':
usmjeri.cpp:92:13: warning: unused variable 'v' [-Wunused-variable]
         int v = vr[i];
             ^
usmjeri.cpp:66:9: warning: 'beg' may be used uninitialized in this function [-Wmaybe-uninitialized]
     int v = beg, p = -1;
         ^
# Verdict Execution time Memory Grader output
1 Correct 240 ms 26864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 450 ms 37036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 15 ms 14464 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 14464 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 15 ms 14720 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 14720 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 223 ms 28000 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 226 ms 27768 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 227 ms 27948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 244 ms 27640 KB Output isn't correct
2 Halted 0 ms 0 KB -