alexjercan/bugnet huggingface dataset:
Problem p00341 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int main() {
  int a[12];
  for (int i = 0; i < 12; i++)
    cin >> a[i];
  sort(a, a + 12);
  bool l = true;
  int b[12][2], c = 0;
  for (int i = 0; i < 12; i++) {
    if (i == 0) {
      b[c][0] = a[i];
      b[c][1] = 1;
      c++;
    } else {
      if (b[c - 1][0] == a[i]) {
        b[c - 1][1]++;
      } else {
        b[c][0] = a[i];
        b[c][1] = 1;
        c++;
      }
    }
  }
  if (c == 3) {
    for (int i = 0; i < c; i++) {
      if (b[i][1] != 4) {
        l = false;
      }
    }
  } else if (c == 2) {
    if ((b[0][1] == 8 && b[1][1] == 4) || (b[0][1] == 4 && b[1][1] == 8)) {
      l = true;
    } else
      l = false;
  } else if (c == 1) {
    if (b[0][1] == 12)
      l = true;
    else
      l = false;
  } else {
    l = false;
  }
  if (l)
    cout << "yes" << endl;
  else
    cout << "no" << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int main() {
  int a[12];
  while (true) {
    for (int i = 0; i < 12; i++)
      cin >> a[i];
    sort(a, a + 12);
    bool l = true;
    int b[12][2], c = 0;
    for (int i = 0; i < 12; i++) {
      if (i == 0) {
        b[c][0] = a[i];
        b[c][1] = 1;
        c++;
      } else {
        if (b[c - 1][0] == a[i]) {
          b[c - 1][1]++;
        } else {
          b[c][0] = a[i];
          b[c][1] = 1;
          c++;
        }
      }
    }
    if (c == 3) {
      for (int i = 0; i < c; i++) {
        if (b[i][1] != 4) {
          l = false;
        }
      }
    } else if (c == 2) {
      if ((b[0][1] == 8 && b[1][1] == 4) || (b[0][1] == 4 && b[1][1] == 8)) {
        l = true;
      } else
        l = false;
    } else if (c == 1) {
      if (b[0][0] == 12)
        l = true;
      else
        l = false;
    } else {
      l = false;
    }
    if (l)
      cout << "yes" << endl;
    else
      cout << "no" << endl;
  }
}
Problem p00341 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  int a[12];
  int i, j;
  int cut = 0;
  int b[3] = {1, 5, 9};
  for (i = 0; i < 12; i++) {
    cin >> a[i];
  }
  for (i = 0; i < 12; i++) {
    for (j = 11; j > i; j--) {
      if (a[i] > a[j]) {
        swap(a[i], a[j]);
      }
    }
  }
  // cout<<"a"<<endl;
  for (i = 0; i < 3; i++) {
    for (j = b[i]; j <= b[i] + 2; j++) {
      if (a[b[i] - 1] == a[j]) {
        cut++;
      }
    }
  }
  if (cut == 9) {
    cout << "yes" << endl;
  } else {
    cout << "no" << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  int a[12];
  int i, j;
  int cut = 0;
  int b[3] = {1, 5, 9};
  for (i = 0; i < 12; i++) {
    cin >> a[i];
  }
  for (i = 0; i < 12; i++) {
    for (j = 11; j > i; j--) {
      if (a[i] > a[j]) {
        swap(a[i], a[j]);
      }
    }
  }
  for (i = 0; i = 3; i++) {
    for (j = b[i]; j < b[i] + 2; j++) {
      if (b[i] == a[j]) {
        cut++;
      }
    }
  }
  if (cut == 12) {
    cout << "yes" << endl;
  } else {
    cout << "no" << endl;
  }
  return 0;
}
Problem p00342 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
long long a[1001], i, ma = 100000, p, n;
long double m1, m2;
int main() {
  cin >> n;
  for (; i < n; i++)
    cin >> a[i];
  sort(a, a + n);
  m1 = (double)(a[n - 1] + a[n - 2]) / (a[1] - a[0]);
  for (i = n - 1; i > 0; i--)
    if (a[i] - a[i - 1] <= ma) {
      ma = a[i] - a[i - 1];
      p = i;
    }
  for (i = n - 1; i > 0; i -= 2)
    if (i != p) {
      m2 = (double)(a[i - 1] + a[i]) / (a[p] - a[p - 1]);
      break;
    }
  m1 = max(m1, m2);
  printf("%.9Lf\\n", m1);
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int a[12], i, ma = 100000, p, n;
double m1, m2;
int main() {
  cin >> n;
  for (; i < n; i++)
    cin >> a[i];
  sort(a, a + n);
  m1 = (double)(a[n - 1] + a[n - 2]) / (a[1] - a[0]);
  for (i = n - 1; i > 0; i--)
    if (a[i] - a[i - 1] <= ma) {
      ma = a[i] - a[i - 1];
      p = i;
    }
  for (i = n - 1; i > 0; i -= 2)
    if (i != p) {
      m2 = (double)(a[i - 1] + a[i]) / (a[p] - a[p ^ 1]);
      break;
    }
  m1 = max(m1, m2);
  printf("%f\\n", m1);
}
Problem p00342 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <vector>

using namespace std;

double calFormula(const int64_t &A, const int64_t &B, const int64_t &C,
                  const int64_t &D) {
  return (double)(A + B) / (C - D);
}

int main() {

  int N;
  cin >> N;

  vector<int64_t> list(N);
  for (int i = 0; i < N; i++) {
    cin >> list[i];
  }

  sort(list.begin(), list.end());
  reverse(list.begin(), list.end());

  double max_val = 0;
  // loop

  for (int a = 0; a < N; a++) {
    if (a > 10) {
      break;
    }
    for (int b = a + 1; b < N; b++) {
      if (b > 10) {
        break;
      }
      for (int c = 0; c < N; c++) {
        if (a == c || b == c) {
          continue;
        }
        for (int d = c + 1; d < N; d++) {
          if (a == d || b == d) {
            continue;
          }
          max_val =
              max(max_val, calFormula(list[a], list[b], list[c], list[d]));
        }
      }
    }
  }

  cout << fixed << setprecision(5);
  cout << max_val << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <vector>

using namespace std;

double calFormula(const int64_t &A, const int64_t &B, const int64_t &C,
                  const int64_t &D) {
  return (double)(A + B) / (C - D);
}

int main() {

  int N;
  cin >> N;

  vector<int64_t> list(N);
  for (int i = 0; i < N; i++) {
    cin >> list[i];
  }

  sort(list.begin(), list.end());
  reverse(list.begin(), list.end());

  double max_val = 0;
  // loop

  for (int a = 0; a < N; a++) {
    for (int b = a + 1; b < N; b++) {
      for (int c = 0; c < N; c++) {
        if (a == c || b == c) {
          continue;
        }
        for (int d = c + 1; d < N; d++) {
          if (a == d || b == d) {
            continue;
          }
          max_val =
              max(max_val, calFormula(list[a], list[b], list[c], list[d]));
        }
      }
    }
  }

  cout << fixed << setprecision(5);
  cout << max_val << endl;

  return 0;
}
Problem p00342 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  int A1 = 0;
  int B1 = 0;
  int C1 = 0;
  int D1 = 0;
  int A2 = 0;
  int B2 = 0;
  int C2 = 0;
  int D2 = 0;
  int enter;
  unsigned long long min = 1000000000000;
  int min_x;
  int min_y;
  int i, j;
  cin >> n;
  vector<int> ent;
  vector<int> a;
  vector<int> b;
  for (i = 0; i < n; i++) {
    cin >> enter;
    ent.push_back(enter);
  }
  sort(ent.begin(), ent.end(), greater<int>());
  for (i = 0; i < n; i++) {
    a.push_back(ent[i]);
    b.push_back(ent[i]);
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) {
      if (a[i] - a[j] > 0) {
        if (a[i] - a[j] < min) {
          min = a[i] - a[j];
          min_x = i;
          min_y = j;
        }
      }
    }
  }

  C1 = a[min_x];
  D1 = a[min_y];

  a.erase(a.begin() + min_x);

  a.erase(a.begin() + min_y - 1);

  A1 = a[0];
  B1 = a[1];

  A2 = b[0];
  B2 = b[1];

  b.erase(b.begin());
  b.erase(b.begin());

  min = 1000000000000;
  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) {
      if (b[i] - b[j] > 0) {
        if (b[i] - b[j] < min) {
          min = b[i] - b[j];
          min_x = i;
          min_y = j;
        }
      }
    }
  }
  C2 = b[min_x];
  D2 = b[min_y];

  if ((A1 + B1) / (C1 - D1) > (A2 + B2) / (C2 - D2)) {
    printf("%16f\\n", (double)(A1 + B1) / (C1 - D1));
  } else {
    printf("%16f\\n", (double)(A2 + B2) / (C2 - D2));
  }

  return 0;
}


Error: -6
double free or corruption (out)


Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  int A1 = 0;
  int B1 = 0;
  int C1 = 0;
  int D1 = 0;
  int A2 = 0;
  int B2 = 0;
  int C2 = 0;
  int D2 = 0;
  int enter;
  int min = 100000;
  int min_x;
  int min_y;
  int i, j;
  cin >> n;
  vector<int> a;
  vector<int> b;
  for (i = 0; i < n; i++) {
    cin >> enter;
    a.push_back(enter);
    b.push_back(enter);
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) {
      if (a[i] - a[j] > 0) {
        if (a[i] - a[j] < min) {
          min = a[i] - a[j];
          min_x = i;
          min_y = j;
        }
      }
    }
  }

  C1 = a[min_x];
  D1 = a[min_y];

  a.erase(a.begin() + min_x);

  a.erase(a.begin() + min_y - 1);

  sort(a.begin(), a.end(), greater<int>());

  A1 = a[0];
  B1 = a[1];

  sort(b.begin(), b.end(), greater<int>());
  A2 = b[0];
  B2 = b[1];
  b.erase(b.begin());
  b.erase(b.begin());

  min = 1000000;
  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) {
      if (b[i] - b[j] > 0) {
        if (b[i] - b[j] < min) {
          min = b[i] - b[j];
          min_x = i;
          min_y = j;
        }
      }
    }
  }
  C2 = b[min_x];
  D2 = b[min_y];

  if ((A1 + B1) / (C1 - D1) > (A2 + B2) / (C2 - D2)) {
    printf("%16f\\n", (float)(A1 + B1) / (C1 - D1));
  } else {
    printf("%16f\\n", (float)(A2 + B2) / (C2 - D2));
  }

  return 0;
}
Problem p00342 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int a[1001], i, ma = 100000, p, n;
double m1, m2;
int main() {
  for (cin >> n; i < n; i++)
    cin >> a[i];
  sort(a, a + n);
  m1 = (double)(a[n - 1] + a[n - 2]) / (a[1] - a[0]);
  for (i = n - 1; i > 0; i--)
    if (a[i] - a[i - 1] <= ma) {
      ma = a[i] - a[i - 1];
      p = i;
    }
  for (i = n - 1; i > 0; i -= 2)
    if (i != p) {
      m2 = (double)(a[i - 1] + a[i]) / (a[p] - a[p - 1]);
      break;
    }
  m1 = max(m1, m2);
  printf("%.9f\\n", m1);
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int a[1001], i, ma = 100000, p, n;
double m1, m2;
int main() {
  for (cin >> n; i < n; i++)
    cin >> a[i];
  sort(a, a + n);
  m1 = (double)(a[n - 1] + a[n - 2]) / (a[1] - a[0]);
  for (i = n - 1; i > 0; i--)
    if (a[i] - a[i - 1] <= ma)
      ma = a[i] - a[i++ - 1];
  for (i = n - 1; i > 0; i -= 2)
    if (i != p) {
      m2 = (double)(a[i - 1] + a[i]) / (a[p] - a[p - 1]);
      break;
    }
  m1 = max(m1, m2);
  printf("%.9f\\n", m1);
}
Problem p00343 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef set<int> S;
bool dfs(bool t, S a, S b, int c, int d) {
  // cout << t << " " << c << " " << d << endl;
  if (a.size() == 0)
    return true;
  if (b.size() == 0)
    return false;
  bool f;
  S n;
  if (t) {
    f = false;
    if (a.find(c - 1) != a.end()) {
      n = a;
      n.erase(c - 1);
      f |= dfs(!t, n, b, c - 1, d);
    }
    if (a.find(d + 1) != a.end()) {
      n = a;
      n.erase(d + 1);
      f |= dfs(!t, n, b, c, d + 1);
    }
    if (a.find(c - 1) == a.end() && a.find(d + 1) == a.end()) {
      f = dfs(!t, a, b, c, d);
    }
  } else {
    f = true;
    if (b.find(c - 1) != b.end()) {
      n = b;
      n.erase(c - 1);
      f &= dfs(!t, a, n, c - 1, d);
    }
    if (b.find(d + 1) != b.end()) {
      n = b;
      n.erase(d + 1);
      f &= dfs(!t, a, n, c, d + 1);
    }
    if (b.find(c - 1) == b.end() && b.find(d + 1) == b.end()) {
      f = dfs(!t, a, b, c, d);
    }
  }
  return f;
}

int main() {
  int N, i, k;
  cin >> N;
  while (N--) {
    S a, b;
    bool u[13] = {};
    u[6] = 1;
    for (i = 0; i < 6; i++) {
      cin >> k;
      u[k - 1] = 1;
      a.insert(k);
    }
    k = 0;
    for (i = 0; i < 13; i++) {
      if (!u[i]) {
        b.insert(i + 1);
        k++;
      }
    }
    cout << (dfs(1, a, b, 7, 7) ? "yes" : "no") << endl;
  }
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int p = 0, i = 0, j, k, b = 1;

  while (s[i] != '.')
    p = p * 10 + s[i] - '0', i++;
  i++;
  while (i < s.size() && s[i] != '(') {
    b *= 10;
    p = p * 10 + s[i] - '0';
    i++;
  }
  if (s[i] == '(') {
    i++;
    j = 0;
    k = 0;
    while (s[i] != ')') {
      k = k * 10 + 9;
      j = j * 10 + s[i] - '0';
      i++;
    }
    b *= k;
    p = p * k + j;
  }
  cout << p / __gcd(p, b) << "/" << b / __gcd(p, b) << endl;
  return 0;
}
Problem p00344 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <map>
#include <vector>
using namespace std;
int S[200000], n, R[200000];
bool used[200000];
int W[200000];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> S[i];
    S[i] %= n;
  }
  for (int i = 0; i < n; i++) {
    R[i] = (i + S[i]) % n;
  }
  for (int i = 0; i < n; i++) {
    if (used[i] == true)
      continue;
    int c = i;
    vector<int> vec, vec2;
    while (true) {
      if (used[c] == true)
        break;
      W[c]++;
      if (W[c] >= 3)
        break;
      if (W[c] == 2)
        vec.push_back(c);
      if (W[c] == 1)
        vec2.push_back(c);
      c = R[c];
    }
    for (int j = 0; j < vec.size(); j++) {
      used[vec[j]] = true;
    }
    for (int j = 0; j < vec2.size(); j++)
      W[vec2[j]] = 0;
  }
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (used[i] == true)
      cnt++;
  }
  cout << cnt << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <map>
#include <vector>
using namespace std;
int S[200000], n, R[200000];
bool used[200000];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> S[i];
    S[i] %= n;
  }
  for (int i = 0; i < n; i++) {
    R[i] = (i + S[i]) % n;
  }
  for (int i = 0; i < n; i++) {
    if (used[i] == true)
      continue;
    map<int, int> M;
    int c = i;
    vector<int> vec;
    while (true) {
      if (used[c] == true)
        break;
      M[c]++;
      if (M[c] >= 3)
        break;
      if (M[c] == 2)
        vec.push_back(c);
      c = R[c];
    }
    for (int j = 0; j < vec.size(); j++) {
      used[vec[j]] = true;
    }
  }
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (used[i] == true)
      cnt++;
  }
  cout << cnt << endl;
  return 0;
}
Problem p00344 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

bool a[100000], s[100000];
int b[100000], c[100000];
signed main() {
  int d, sum = 0;
  cin >> d;
  for (int e = 0; e < d; e++) {
    scanf("%d", &b[e]);
  }
  for (int i = 0; i < d; i++) {
    if (!a[i]) {
      memset(c, 0, sizeof(c));
      int now = i;
      while (1) {
        a[now] = true;
        if (c[now] == 2)
          break;
        else if (c[now] == 1)
          s[now] = true;
        c[now]++;
        now += b[now];
        now %= d;
      }
    }
  }
  for (bool u : s)
    sum += u;
  cout << sum << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

bool a[10000], s[10000];
int b[10000], c[10000];
signed main() {
  int d, sum = 0;
  cin >> d;
  for (int e = 0; e < d; e++) {
    scanf("%d", &b[e]);
  }
  for (int i = 0; i < d; i++) {
    if (!a[i]) {
      memset(c, 0, sizeof(c));
      int now = i;
      while (1) {
        a[now] = true;
        if (c[now] == 2)
          break;
        else if (c[now] == 1)
          s[now] = true;
        c[now]++;
        now += b[now];
        now %= d;
      }
    }
  }
  for (bool u : s)
    sum += u;
  cout << sum << endl;
}
Problem p00344 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, n) for (int i = n - 1; i >= 0; --i)
#define yesno(flg)                                                             \\
  if (flg) {                                                                   \\
    cout << "yes" << endl;                                                     \\
  } else {                                                                     \\
    cout << "no" << endl;                                                      \\
  }
#define vi vector<int>
#define MAX_N 200005
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P1;
typedef pair<int, P1> P2;
const int inf = 1000000000;
P1 xy[MAX_N] = {};
bool dp[100001] = {};

int main() {
  int n;
  cin >> n;
  int a[100001];
  rep(i, n) cin >> a[i];
  int t = 0;

  rep(i, n) {
    if (dp[i])
      continue;
    bool dp2[100001] = {};
    dp[i] = true;
    dp2[i] = true;
    int k = (i + a[i]) % n;
    while (1) {
      if (dp2[k]) {
        if (k == i) {
          // success
          t++;
          k = (k + a[k]) % n;
          while (k != i) {
            t++;
            dp[k] = true;
            k = (k + a[k]) % n;
          }
        }
        break;
      }
      if (dp[k]) {
        //				rep(j,n){
        //					if(dp2[j])dp[j]=true;
        //					//false
        //				}
        //				break;
      }
      dp2[k] = true;
      k = (k + a[k]) % n;
    }
  }
  cout << t << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, n) for (int i = n - 1; i >= 0; --i)
#define yesno(flg)                                                             \\
  if (flg) {                                                                   \\
    cout << "yes" << endl;                                                     \\
  } else {                                                                     \\
    cout << "no" << endl;                                                      \\
  }
#define vi vector<int>
#define MAX_N 200005
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P1;
typedef pair<int, P1> P2;
const int inf = 1000000000;
P1 xy[MAX_N] = {};
bool dp[100001] = {};

int main() {
  int n;
  cin >> n;
  int a[100001];
  rep(i, n) cin >> a[i];
  int t = 0;

  rep(i, n) {
    if (dp[i])
      continue;
    bool dp2[100001] = {};
    dp[i] = true;
    dp2[i] = true;
    int k = (i + a[i]) % n;
    while (1) {
      if (dp2[k]) {
        if (k == i) {
          // success
          rep(j, n) {
            if (dp2[j]) {
              t++;
              dp[j] = true;
            }
          }
        }
        break;
      }
      if (dp[k]) {
        //				rep(j,n){
        //					if(dp2[j])dp[j]=true;
        //					//false
        //				}
        //				break;
      }
      dp2[k] = true;
      k = (k + a[k]) % n;
    }
  }
  cout << t << endl;
  return 0;
}
Problem p00345 (C++) — buggy submission, verdict: Runtime Error

#include <cmath>
#include <iostream>
#include <string>
using namespace std;
string S;
int e, f1, f2, g1, g2;
int gcd(int a, int b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
int main() {
  cin >> S;
  string T;
  bool flag = false;
  for (int i = 0; i < S.size(); i++) {
    if (S[i] == '.') {
      e = stoi(T);
      T = "";
    } else if (S[i] == '(') {
      if (T.size() >= 1) {
        f1 = stoi(T);
      }
      f2 = pow(10, T.size());
      T = "";
      flag = true;
    } else if (S[i] == ')') {
      g1 = stoi(T);
      g2 = pow(10, T.size()) - 1;
      T = "";
    } else {
      T += S[i];
    }
  }
  if (flag == false) {
    f1 = stoi(T);
    f2 = pow(10, T.size());
    g1 = 0;
    g2 = 1;
  }
  int E1 = e * f2 * g2 + f1 * g2 + g1, E2 = f2 * g2;
  cout << E1 / gcd(E1, E2) << "/" << E2 / gcd(E1, E2) << endl;
  return 0;
}

Error: -6
terminate called after throwing an instance of 'std::invalid_argument'
  what():  stoi


Fixed submission:

#include <cmath>
#include <iostream>
#include <string>
using namespace std;
string S;
int e, f1, f2, g1, g2;
int gcd(int a, int b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
int main() {
  cin >> S;
  string T;
  bool flag = false;
  for (int i = 0; i < S.size(); i++) {
    if (S[i] == '.') {
      e = stoi(T);
      T = "";
    } else if (S[i] == '(') {
      f1 = stoi(T);
      f2 = pow(10, T.size());
      T = "";
      flag = true;
    } else if (S[i] == ')') {
      g1 = stoi(T);
      g2 = pow(10, T.size()) - 1;
      T = "";
    } else {
      T += S[i];
    }
  }
  if (flag == false) {
    f1 = stoi(T);
    f2 = pow(10, T.size());
    g1 = 0;
    g2 = 1;
  }
  int E1 = e * f2 * g2 + f1 * g2 + g1, E2 = f2 * g2;
  cout << E1 / gcd(E1, E2) << "/" << E2 / gcd(E1, E2) << endl;
  return 0;
}
Problem p00346 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>

const int LIM = 1.5e3 + 5;

struct data {
  int x, d;
};
bool operator<(data a, data b) { return a.d > b.d; }

int n, m, dis[LIM][LIM], max, ans;
std::vector<data> edg[LIM];
bool chk[LIM], vis[LIM];
std::priority_queue<data> q;

void dijkstra(int s, int *dis) {
  q.push({s, 0});
  while (!q.empty()) {
    data x = q.top();
    q.pop();
    if (!vis[x.x]) {
      vis[x.x] = true;
      dis[x.x] = x.d;
      for (data y : edg[x.x])
        if (!vis[y.x])
          q.push({y.x, x.d + y.d});
    }
  }
}

void trace(int x, int *dis) {
  vis[x] = true;
  if (!chk[x]) {
    --ans;
    chk[x] = true;
  }
  for (data y : edg[x])
    if (!vis[y.x] && dis[y.x] == dis[x] - y.d)
      trace(y.x, dis);
}

int main() {
  scanf("%d%d", &n, &m);
  while (m--) {
    int u, v, d;
    scanf("%d%d%d", &u, &v, &d);
    edg[u].push_back({v, d});
    edg[v].push_back({u, d});
  }

  for (int i = 1; i <= n; ++i) {
    memset(vis, 0x00, sizeof(vis));
    dijkstra(i, dis[i]);
    for (int j = 1; j <= n; ++j)
      max = std::max(max, dis[i][j]);
  }

  for (int i = 1; i <= n; ++i) {
    memset(vis, 0x00, sizeof(vis));
    for (int j = 1; j <= n; ++j)
      if (dis[i][j] == max)
        trace(j, dis[i]);
  }

  printf("%d\\n", ans + n);
  for (int i = 1; i <= n; ++i)
    if (!chk[i])
      printf("%d\\n", i);
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>

const int LIM = 1.5e3 + 5;

struct data {
  int x, d;
};
bool operator<(data a, data b) { return a.d > b.d; }

int n, m, dis[LIM][LIM], max, ans;
std::vector<data> edg[LIM];
bool chk[LIM], vis[LIM];
std::priority_queue<data> q;

void dijkstra(int s, int *dis) {
  q.push({s, 0});
  while (!q.empty()) {
    data x = q.top();
    q.pop();
    if (!vis[x.x]) {
      vis[x.x] = true;
      dis[x.x] = x.d;
      for (data y : edg[x.x])
        if (!vis[y.x])
          q.push({y.x, x.d + y.d});
    }
  }
}

void trace(int x, int *dis) {
  if (!chk[x]) {
    --ans;
    chk[x] = true;
  }
  for (data y : edg[x])
    if (!vis[y.x] && dis[y.x] == dis[x] - y.d)
      trace(y.x, dis);
}

int main() {
  scanf("%d%d", &n, &m);
  while (m--) {
    int u, v, d;
    scanf("%d%d%d", &u, &v, &d);
    edg[u].push_back({v, d});
    edg[v].push_back({u, d});
  }

  for (int i = 1; i <= n; ++i) {
    memset(vis, 0x00, sizeof(vis));
    dijkstra(i, dis[i]);
    for (int j = 1; j <= n; ++j)
      max = std::max(max, dis[i][j]);
  }

  for (int i = 1; i <= n; ++i) {
    memset(vis, 0x00, sizeof(vis));
    for (int j = 1; j <= n; ++j)
      if (dis[i][j] == max)
        trace(j, dis[i]);
  }

  printf("%d\\n", ans + n);
  for (int i = 1; i <= n; ++i)
    if (!chk[i])
      printf("%d\\n", i);
}