Submission #960732

#TimeUsernameProblemLanguageResultExecution timeMemory
960732GrindMachine007 (CEOI14_007)C++17
100 / 100
217 ms36040 KiB
#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> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; typedef long long int ll; typedef long double ld; typedef pair<int,int> pii; typedef pair<ll,ll> pll; #define fastio ios_base::sync_with_stdio(false); cin.tie(NULL) #define pb push_back #define endl '\n' #define sz(a) (int)a.size() #define setbits(x) __builtin_popcountll(x) #define ff first #define ss second #define conts continue #define ceil2(x,y) ((x+y-1)/(y)) #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define yes cout << "Yes" << endl #define no cout << "No" << endl #define rep(i,n) for(int i = 0; i < n; ++i) #define rep1(i,n) for(int i = 1; i <= n; ++i) #define rev(i,s,e) for(int i = s; i >= e; --i) #define trav(i,a) for(auto &i : a) template<typename T> void amin(T &a, T b) { a = min(a,b); } template<typename T> void amax(T &a, T b) { a = max(a,b); } #ifdef LOCAL #include "debug.h" #else #define debug(x) 42 #endif /* read the edi some time ago, remember some ideas from there */ const int MOD = 1e9 + 7; const int N = 2e5 + 5; const int inf1 = int(1e9) + 5; const ll inf2 = ll(1e18) + 5; vector<int> adj1[N], adj2[N]; vector<bool> vis(N); vector<int> topo; void dfs1(int u){ vis[u] = 1; trav(v,adj2[u]){ if(vis[v]) conts; dfs1(v); } topo.pb(u); } void solve(int test_case) { int n,m; cin >> n >> m; int s,d,x,y; cin >> s >> d >> x >> y; rep1(i,m){ int u,v; cin >> u >> v; adj1[u].pb(v), adj1[v].pb(u); } auto bfs = [&](int src){ queue<int> q; vector<int> dis(n+5,inf1); q.push(src); dis[src] = 0; while(!q.empty()){ int u = q.front(); q.pop(); trav(v,adj1[u]){ if(dis[v] != inf1) conts; q.push(v); dis[v] = dis[u]+1; } } return dis; }; auto disd = bfs(d); auto disx = bfs(x); auto disy = bfs(y); rep1(u,n){ trav(v,adj1[u]){ if(disx[v] == disx[u]-1 and disy[v] == disy[u]-1){ adj2[u].pb(v); } } } rep1(i,n){ if(vis[i]) conts; dfs1(i); } vector<int> dp(n+5); trav(u,topo){ trav(v,adj2[u]){ amax(dp[u],dp[v]+1); } } vector<bool> win(n+5); // does 007 win if dr.null starts at u (no turns skipped)? rep1(u,n){ int x1 = disx[s], y1 = disy[s]; int x2 = disx[u], y2 = disy[u]; bool curr_win; if(x2 < x1 or y2 < y1){ curr_win = false; } else{ if(x1 < x2 or y1 < y2){ curr_win = true; } else{ if(dp[u] > dp[s]){ curr_win = false; } else{ curr_win = true; } } } win[u] = curr_win; } vector<bool> dis_win(n+5,1); rep1(u,n){ if(!win[u]){ // cant wait for time = dis(u,d) dis_win[disd[u]] = 0; } } int ans = -1; rep(i,n+1){ if(!dis_win[i]) break; ans = i; } cout << ans << endl; } int main() { fastio; int t = 1; // cin >> t; rep1(i, t) { solve(i); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...