제출 #1171344

#제출 시각아이디문제언어결과실행 시간메모리
1171344belgianbotFile Paths (BOI15_fil)C++20
33 / 100
1092 ms1320 KiB
/* AUTHOR : BELGIANBOT */ #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; template<typename T> void read(T& x) { cin >> x;} template<typename T1, typename T2> void read(pair<T1, T2>& p) { read(p.first), read(p.second);} template<typename T> void read(vector<T>& v) { for (auto& x : v) read(x); } template<typename T1, typename T2> void read(T1& x, T2& y) { read(x), read(y); } template<typename T1, typename T2, typename T3> void read(T1& x, T2& y, T3& z) { read(x), read(y), read(z); } template<typename T1, typename T2, typename T3, typename T4> void read(T1& x, T2& y, T3& z, T4& zz) { read(x), read(y), read(z), read(zz); } template<typename T> void print(vector<T>& v) { for (auto& x : v) cout << x << ' '; cout << endl; } #define quit(x) return (void)(cout << x << endl) #define pb push_back #define fi first #define se second #define ordered_set tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define mp make_pair #define sz(x) (int)(x.size()) #define YES cout<<"YES\n" #define NO cout<<"NO\n" #define QYES quit("YES") #define QNO quit("NO") #define cmin(a, b) a = min(a, b) #define cmax(a, b) a = max(a, b) #define int long long #define double long double const int inf = numeric_limits<int>::max() / 4; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int MOD = 1e9+7, LOG=20; void solve(); signed main() { ios::sync_with_stdio(false); cin.tie(0); int t = 1; //cin >> t; while (t--) solve(); return 0; } int k, n, m, p, q, s; vector<vector<pair<int,int>>> adj, file; vector<bool> ok; vector<int> path, nodePath; bool find(int x, int sum, int w, int in) { auto it = find(all(path), sum + s + w - k); if (it != path.end()) return true; if (n <= 500 && m <= 500) { int index = find(all(nodePath), in) - nodePath.begin(); for (int i = 1; i <= sqrt(k-w); i++) { if ((k-w)%i) continue; auto it2 = find(path.begin(), path.begin()+index+1, sum + s - i); if (it2 != path.begin()+index+1) return true; it2 = find(path.begin(), path.begin()+index+1, sum + s - ((k-w)/i)); if (it2 != path.begin()+index+1) return true; } } bool win = false; for (auto [y, weight] : adj[x]) { if (find(all(nodePath), y) != nodePath.end()) { win = find(y, sum + weight, w, y); } else win = find(y, sum + weight, w, in); if (win) return true; } return false; } void dfs(int x, int sum) { nodePath.push_back(x); path.push_back(sum); for (auto [f, w] : file[x]) { ok[f] = (find(0, 0, sum + w, 0) || sum + w == k); } for (auto [y, weight] : adj[x]) dfs(y, sum + weight); nodePath.pop_back(); path.pop_back(); } void solve() { cin >> n >> m >> k >> s; s++; adj.resize(n+1); ok.resize(m, false); file.resize(n+1); for (int i = 1; i <= n; i++) { int a, b; cin >> a >> b; adj[a].push_back({i,b+1}); } for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; file[a].push_back({i, b+1}); } dfs(0, 0); for (auto x : ok) { if (x) cout << "YES\n"; else cout <<"NO\n"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...