Problem p02689 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
typedef long long ll;
#define all(x) (x).begin(), (x).end() // sortなどの引数を省略
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define max3(x, y, z) max(x, max(y, z))

#ifdef _MSC_FULL_VER // デバッグ出力
#define dout cout
#define debug() if (true)
#define check(x) std::cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) std::cout << "☆" << x << endl
#else
#define dout                                                                   \\
  if (false)                                                                   \\
  cout
#define debug() if (false)
#define check(x)                                                               \\
  if (false)                                                                   \\
  cout << "★" << #x << "の値:" << (x) << endl
#define pass(x)                                                                \\
  if (false)                                                                   \\
  cout << "☆" << x << endl
#endif
using namespace std;

int main() {
  int a, b;
  cin >> a >> b;
  int tmp, tmps;
  vector<int> list(a);
  vector<int> flags(a);
  for (int i = 0; i < a; i++) {
    cin >> list[i];
  }
  int ans = 0;
  rep(i, b) {
    cin >> tmp >> tmps;
    tmp--;
    tmps--;
    if (list[tmp] >= list[tmps]) {
      flags[tmps] = 1;
    }
    if (list[tmp] <= list[tmps]) {
      flags[tmp] = 1;
    }
  }
  rep(i, a) {
    if (flags[i] == 0) {
      ans++;
    }
  }
  cout << ans;
}
/*
//よく使うやつ
int N;
cin >> N;
vector<int> list(N);
for (int i = 0; i < N; i++) {
cin >> list[i];
}
// for文
for (int i = 0; i < N; i++) {
}
//配列
vector<int> list;
list.at(i)
vector<vector<int>> list(10, vector<int>(10));
sort(all(list));
sort(all(list), greater<int>());
//配列の内容表示
dout << "====listの内容====\\n";
for (int i = 0; i < N; i++) dout << list[i] << endl;
dout << "====ここまで====\\n";
*/


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
typedef long long ll;
#define all(x) (x).begin(), (x).end() // sortなどの引数を省略
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define max3(x, y, z) max(x, max(y, z))

#ifdef _MSC_FULL_VER // デバッグ出力
#define dout cout
#define debug() if (true)
#define check(x) std::cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) std::cout << "☆" << x << endl
#else
#define dout                                                                   \\
  if (false)                                                                   \\
  cout
#define debug() if (false)
#define check(x)                                                               \\
  if (false)                                                                   \\
  cout << "★" << #x << "の値:" << (x) << endl
#define pass(x)                                                                \\
  if (false)                                                                   \\
  cout << "☆" << x << endl
#endif
using namespace std;

int main() {
  int a, b;
  cin >> a >> b;
  int tmp, tmps;
  vector<int> list(a);
  for (int i = 0; i < a; i++) {
    cin >> list[i];
  }
  vector<vector<int>> way(a, vector<int>(a, 0));
  rep(i, b) {
    cin >> tmp >> tmps;
    way[tmp - 1][tmps - 1] = 1;
    way[tmps - 1][tmp - 1] = 1;
  }
  int flag = 0;
  int ans = 0;
  rep(i, a) {
    flag = 0;
    rep(j, a) {
      if (way[i][j] == 1 && i != j) {
        if (list[j] >= list[i]) {
          flag = 1;
        }
      }
    }
    if (flag == 0) {
      ans++;
    }
  }
  cout << ans;
}
/*
//よく使うやつ
int N;
cin >> N;
vector<int> list(N);
for (int i = 0; i < N; i++) {
cin >> list[i];
}
// for文
for (int i = 0; i < N; i++) {
}
//配列
vector<int> list;
list.at(i)
vector<vector<int>> list(10, vector<int>(10));
sort(all(list));
sort(all(list), greater<int>());
//配列の内容表示
dout << "====listの内容====\\n";
for (int i = 0; i < N; i++) dout << list[i] << endl;
dout << "====ここまで====\\n";
*/