QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#140829#5160. Kebab PizzaMuhammadSawalhy#WA 1ms3464kbC++142.2kb2023-08-16 21:03:552023-08-16 21:03:55

Judging History

你现在查看的是最新测评结果

  • [2023-08-16 21:03:55]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3464kb
  • [2023-08-16 21:03:55]
  • 提交

answer

// ﷽
#include <bits/stdc++.h>

using namespace std;

#ifdef SAWALHY
#include "debug.hpp"
#else
#define debug(...) 0
#define debug_itr(...) 0
#define debug_bits(...) 0
#endif

#define ll long long
#define int long long
#define all(v) v.begin(), v.end()

template <typename Edge> class DirectedEulerian {
public:
  int n, m;
  vector<vector<pair<int, Edge>>> adj;
  DirectedEulerian(int n, int m, const vector<vector<pair<int, Edge>>> &adj)
      : adj(adj), n(n), m(m) {}

  vector<Edge> path(bool circuit = false) {
    vector<Edge> path;
    int in = 0, out = 0;

    calc_deg();
    int start = -1, end = -1;
    for (int i = 0; i < n; i++) {
      if (indeg[i] > outdeg[i])
        in += indeg[i] - outdeg[i], end = i;
      else if (indeg[i] < outdeg[i])
        out += outdeg[i] - indeg[i], start = i;
    }

    if (m == 0 ||
        !((in == 0 && out == 0) || (in == 1 && out == 1 && !circuit))) {
      return {};
    }

    if (start == -1) {
      assert(end == -1);
      for (int i = 0; i < n; i++) {
        if (outdeg[i] > 0) {
          start = end = i;
          break;
        }
      }
    }

    dfs(start, {}, path);

    path.pop_back();
    reverse(all(path));

    return path;
  }

private:
  vector<int> indeg, outdeg;

  void calc_deg() {
    indeg.assign(n, 0);
    outdeg.assign(n, 0);
    for (int i = 0; i < n; i++) {
      outdeg[i] = adj[i].size();
      for (auto &j : adj[i])
        indeg[j.first]++;
    }
  }

  void dfs(int i, Edge e, vector<Edge> &path) {
    while (outdeg[i] > 0)
      outdeg[i]--, dfs(adj[i][outdeg[i]].first, adj[i][outdeg[i]].second, path);
    path.push_back(e);
  }
};

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL), cout.tie(NULL);

  int n, k;
  cin >> n >> k;

  vector<pair<int, int>> toppings(n);
  vector<set<int>> adj(n);

  for (int i = 0, a, b; i < n; i++) {
    cin >> a >> b;
    a--, b--;
    toppings[i] = {a, b};
    if (a != b) {
      adj[a].insert(b);
      adj[b].insert(a);
    }
  }

  for (int i = 0; i < n; i++) {
      if (adj[i].size() > 2) {
	  cout << "impossible\n";
	  exit(0);
      }
  }

  cout << "possible\n";

  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3464kb

input:

7 6
2 2
3 6
1 1
1 5
4 5
6 6
6 5

output:

impossible

result:

wrong answer 1st lines differ - expected: 'possible', found: 'impossible'