Submission #1123684

#TimeUsernameProblemLanguageResultExecution timeMemory
1123684KhanhDangJoker (BOI20_joker)C++20
25 / 100
369 ms66112 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define pll pair<ll, ll> #define fi first #define se second #define all(v) (v).begin(),(v).end() #define Unique(v) sort(all(v)); (v).erase(unique(all(v)), (v).end()); const ll N = 1e6+5; ll n, m, q; ll x[N], y[N]; ll dd[N], ans[N]; vector<ll> adj[N]; vector<pll> qu[N]; bool dfs(ll u, ll p) { for (auto v : adj[u]) { if (v == p) continue; if (dd[v]) { if (dd[v] % 2 == dd[u] % 2) return true; } else { dd[v] = dd[u] + 1; if (dfs(v, u)) return true; } } return false; } bool check(ll mid, ll id) { for (int i = 1; i < id; i++) { adj[x[i]].push_back(y[i]); adj[y[i]].push_back(x[i]); } for (int i = mid+1; i <= m; i++) { adj[x[i]].push_back(y[i]); adj[y[i]].push_back(x[i]); } fill(dd+1, dd+n+1, 0); bool ok = false; for (int i = 1; i <= n; i++) { if (dd[i]) continue; dd[i] = 1; ok = dfs(i, i); if (ok) break; } for (int i = 1; i <= n; i++) adj[i].clear(); return ok; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define task "NOHOME" if (fopen(task".INP", "r")) { freopen(task".INP", "r", stdin); freopen(task".OUT", "w", stdout); } if (fopen("task.INP", "r")) { freopen("task.INP", "r", stdin); freopen("task.OUT", "w", stdout); } cin>>n>>m>>q; for (int i = 1; i <= m; i++) cin>>x[i]>>y[i]; for (int i = 1; i <= q; i++) { ll l, r; cin>>l>>r; qu[l].push_back({r, i}); } for (int i = 1; i <= n; i++) { if (qu[i].empty()) continue; ll l = i, r = m, res = 0; while (l <= r) { ll mid = (l+r)>>1; if (check(mid, i)) { res = mid; l = mid + 1; } else r = mid - 1; } for (auto v : qu[i]) ans[v.se] = (v.fi <= res) ; } for (int i = 1; i <= q; i++) cout<<(ans[i] ? "YES\n" : "NO\n"); }

Compilation message (stderr)

Joker.cpp: In function 'int main()':
Joker.cpp:54:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   54 |         freopen(task".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Joker.cpp:55:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |         freopen(task".OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Joker.cpp:58:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   58 |         freopen("task.INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Joker.cpp:59:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 |         freopen("task.OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#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...