QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#753065#9548. The Foolucup-team3646#Compile Error//C++202.5kb2024-11-16 11:09:382024-11-16 11:09:41

Judging History

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

  • [2024-11-16 11:09:41]
  • 评测
  • [2024-11-16 11:09:38]
  • 提交

answer

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

using ll = long long;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rep2(i, l, r) for (ll i = l; i < r; i++)

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;

/* ---- */
#define all(A) A.begin(), A.end()
#define elif else if
using pii = pair<ll, ll>;

bool chmin(auto &a, const auto &b) { return a > b ? a = b, 1 : 0; }
bool chmax(auto &a, const auto &b) { return a < b ? a = b, 1 : 0; }

struct IOSetup {
  IOSetup() {
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
} iosetup;

template <class T>
void print(vector<T> a) {
  for (auto x : a) cerr << x << ' ';
  cerr << endl;
}

void print(auto x) { cerr << x << endl; }

template <class Head, class... Tail>
void print(Head &&head, Tail &&...tail) {
  cerr << head << ' ';
  print(forward<Tail>(tail)...);
}

void solve(){
  int n;
  cin>>n;
  vi deg(n);
  vvi edge(n);
  rep(i,n-1){
    int u,v;
    cin>>u>>v;
    u--;v--;
    edge[u].push_back(v);
    edge[v].push_back(u);
    deg[u]++;
    deg[v]++;
  }

  bool ok=true;
  vector<pair<int,int>>ans;
  auto dfs=[&](auto dfs,int v,int p)->pair<int,int>{
    vi ok1,ok2;
    int sz=0;
    for(auto u:edge[v]){
      if(u!=p){
        pair<int,int>res=dfs(dfs,u,v);
        if(res.first!=-1){
          if(res.first==2)ok2.push_back(res.second);
          else ok1.push_back(res.second);
          sz++;
        }
      }
    }
    if(deg[v]%2==1){
      if(!ok2.empty()){
        auto x=ok2.back();
        ok2.pop_back();
        ans.push_back({x,v});
        vi rem;
        for(auto y:ok1)rem.push_back(y);
        for(auto y:ok2)rem.push_back(y);
        while(rem.size()>=2){
          int v1=rem.back();
          rem.pop_back();
          int v2=rem.back();
          rem.pop_back();
          ans.push_back({v1,v2});
        }
        if(rem.size()==1){
          return {2,rem.back()};
        }
        else{
          return {-1,-1};
        }
      }
      elif(sz%2==1){
        ok=false;
        return {-1,-1};
      }
      vi rem;
      for(auto y:ok1)rem.push_back(y);
      for(auto y:ok2)rem.push_back(y);
      while(rem.size()>=2){
        int v1=rem.back();
        rem.pop_back();
        int v2=rem.back();
        rem.pop_back();
        ans.push_back({v1,v2});
      }
      assert((int)(rem.size())==0);
      return {1,v};
    }
  };
  if(ok){
    print(ans.size());
  }
  else{
    print(-1);
  }
}

int main(){
  int T;
  cin>>T;
  rep(i,T)solve();  
}
a

详细

answer.code:124:1: error: ‘a’ does not name a type
  124 | a
      | ^