Submission #69249

#TimeUsernameProblemLanguageResultExecution timeMemory
69249Just_Solve_The_ProblemPort Facility (JOI17_port_facility)C++11
22 / 100
6099 ms49504 KiB
#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define eb emplace_back
#define ll long long
#define pii pair < int, int >
#define fr first
#define sc second
#define mk make_pair
#define sz(s) (int)s.size()
#define all(s) s.begin(), s.end()
#define OK puts("ok");
#define whatis(x) cerr << #x << " = " << x << endl;
#define pause system("pause");

const int N = (int)1e6 + 7;
const int inf = (int)1e9 + 7;
int mod = (int)1e9 + 7;

pii ar[N];

int ans;
int div2;
int dp[N];
int pr[N];
int used[N];
int c[N];
vector < int > edge[N];

int mult(int a, int b) {
  return (a * 1LL * b) % mod;
}

int binpow(int a, int n) {
  int res = 1;
  while (n > 0) {
    if (n & 1)
      res = mult(res, a);
    a = mult(a, a);
    n >>= 1;
  }
  return res;
}

int getpar(int a) {
  if (pr[a] == a) return a;
  return pr[a] = getpar(pr[a]);
}

void connect(int a, int b) {
  a = getpar(a);
  b = getpar(b);
  if (a != b) {
    pr[a] = b;
  }
}

bool bfs(int v) {
  queue < int > q;
  q.push(v);
  used[v] = 1;
  while (!q.empty()) {
    v = q.front();
    q.pop();
    for (int to : edge[v]) {
      if (used[to]) {
        if (used[to] == used[v]) {
          return 0;
        }
      } else {
        used[to] = used[v] % 2 + 1;
        q.push(to);
      }
    }
  }
  return 1;
}

main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d %d", &ar[i].fr, &ar[i].sc);
  }
  iota(pr, pr + n, 0);
  sort(ar, ar + n);
  int ans = 0;
  bool fl = 1;
  for (int i = 1; i < n; i++) {
    int last = -1;
    for (int j = 0; j < i; j++) {
      if (ar[j].sc > ar[i].fr && ar[j].sc < ar[i].sc) {
        connect(i, j);
        edge[i].pb(j);
        edge[j].pb(i);
      }
    }
  }

  for (int i = 0; i < n; i++) {
    if (getpar(i) == i) {
      if (!bfs(i)) {
        fl = 0;
      }
      ans++;
    }
  }
  if (!fl) {
    puts("0");
    return 0;
  }
  cout << binpow(2, ans);
}

Compilation message (stderr)

port_facility.cpp:81:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
port_facility.cpp: In function 'int main()':
port_facility.cpp:92:9: warning: unused variable 'last' [-Wunused-variable]
     int last = -1;
         ^~~~
port_facility.cpp:83:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &n);
   ~~~~~^~~~~~~~~~
port_facility.cpp:85:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &ar[i].fr, &ar[i].sc);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...