Submission #235192

#TimeUsernameProblemLanguageResultExecution timeMemory
235192VimmerUsmjeri (COCI17_usmjeri)C++14
28 / 140
450 ms37036 KiB
#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)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...