답안 #1093528

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1093528 2024-09-27T02:33:31 Z ntdaccode Joker (BOI20_joker) C++17
0 / 100
22 ms 47448 KB
#include<bits/stdc++.h>
#define fori(i,a,b) for(int i=a;i<=b;i++)
#define int long long
#define ii pair<int,int>
#define fi first
#define se second
#define pb push_back
using namespace std;
const int mod=1e9+7;
const int M=1e6+10;
const int N=1e3+10;
int n,m,q;
int x[M],y[M];
vector<int> ke[M];
int dd[M];
bool dfs(int u,int p)
{
  for(int v:ke[u])
  {
    if(v==p) continue;

    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(int mid,int idx)
{
  fori(i,1,idx-1)
  {
    if(x[i]==y[i]) continue;
    ke[x[i]].pb(y[i]);
    ke[y[i]].pb(x[i]);//if(mid==8) cout << x[i] <<" " <<  y[i] << "\n";
  }
  for(int i=mid+1;i<=m;i++)
  {
    if(x[i]==y[i]) continue;
    ke[x[i]].pb(y[i]);//if(mid==8) cout << x[i] <<" " <<  y[i] << "\n";
    ke[y[i]].pb(x[i]);
  }
   fori(i,1,n) dd[i]=0;
    bool ok=0;
    fori(i,1,n)
    {
      if(!dd[i])
      {
        dd[i]=1;
        if(dfs(i,i))
        {
          ok=1;
          break;
        }
      }
    }
    fori(i,1,n) ke[i].clear();
    return ok;
}
vector<ii> Q[M];
int ret[M];
int32_t main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  #define task "1"
  if(fopen(task".inp","r"))
  {
    freopen(task".inp","r",stdin);
    freopen(task".out","w",stdout);
  }
  cin >> n >> m >> q;
  fori(i,1,m) cin >> x[i] >> y[i];int mx=0;
  fori(i,1,q)
  {
    int l,r;
    cin >> l >> r;
    Q[l].pb({r,i});
    mx=max(mx,l);
  }
  fori(i,1,mx)
  {
    if(Q[i].size()==0) continue;
    int l=1,r=m,lim;
    while(l<=r)
    {
      int mid=(l+r)/2;
      if(check(mid,i))
      {
        lim=mid;
        l=mid+1;
      }
      else r=mid-1;
    }
    //cout << lim << " ";
    for(ii v:Q[i]) ret[v.se]=(v.fi<=lim) ;
  }
  fori(i,1,q)
  {
    if(ret[i]) cout << "YES\n";
    else cout << "NO\n";
  }
}


Compilation message

Joker.cpp: In function 'int32_t main()':
Joker.cpp:72:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   72 |     freopen(task".inp","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
Joker.cpp:73:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   73 |     freopen(task".out","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 22 ms 47448 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 22 ms 47448 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 22 ms 47448 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 22 ms 47448 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 22 ms 47448 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 22 ms 47448 KB Output isn't correct
2 Halted 0 ms 0 KB -