Submission #235443

#TimeUsernameProblemLanguageResultExecution timeMemory
235443VEGAnnUsmjeri (COCI17_usmjeri)C++14
28 / 140
371 ms41340 KiB
#include <bits/stdc++.h> #define sz(x) ((int)x.size()) #define all(x) x.begin(),x.end() #define MP make_pair #define ft first #define sd second #define PB push_back #define pli pair<ll,int> using namespace std; typedef long long ll; const int N = 300100; const int PW = 22; const int oo = 2e9; const int md = int(1e9) + 7; vector<int> ins[N], del[N]; multiset<int> mx; int n, m, pr[N], ans = 1; bool mrk[N]; int get(int x) { return (pr[x] == x ? x : pr[x] = get(pr[x])); } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); #ifdef _LOCAL freopen("in.txt","r",stdin); #endif // _LOCAL cin >> n >> m; for (int i = 1; i < n; i++){ int x, y; cin >> x >> y; x--; y--; pr[i] = i; } for (int i = 0; i < m; i++){ int l, r; cin >> l >> r; if (l > r) swap(l, r); l--; r--; ins[l + 1].PB(r); del[r].PB(r); } mx.clear(); for (int i = 1; i < n; i++){ for (int cr : ins[i]) mx.insert(cr); if (sz(mx) > 0) pr[i] = get(*(--mx.end())); for (int cr : del[i]) mx.erase(mx.find(cr)); } for (int i = 1; i < n; i++){ int cur = get(i); if (mrk[cur]) continue; mrk[cur] = 1; ans += ans; if (ans >= md) ans -= md; } cout << ans; return 0; }
#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...