제출 #961046

#제출 시각아이디문제언어결과실행 시간메모리
961046Huseyn123Spring cleaning (CEOI20_cleaning)C++17
34 / 100
1059 ms62436 KiB
#include <bits/stdc++.h>
//#define int ll
#define MAX 1000001
#define INF INT_MAX
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define ins insert
#define ff first
#define ss second 
#define all(a) a.begin(),a.end()
#define lb(a,b) lower_bound(all(a),b)
#define ub(a,b) upper_bound(all(a),b)
#define sortv(a) sort(all(a))
#define outputar(a,b){\
    for(int i=0;i<b;i++){\
        cout << a[i] << " ";\
    }\
    cout << "\n";\
}
#define outputvec(a){\
    for(auto x:a){\
        cout << (int)x << " ";\
    }\
    cout << endl;\
}
#define reset(a,n,v){\
    for(int i=0;i<n;i++){\
        a[i]=v;\
    }\
}
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef tuple<ll,ll,ll> tll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef double db;
typedef long double ldb;
inline void USACO(string filename){
  freopen((filename+".in").c_str(),"r",stdin);
  freopen((filename+".out").c_str(),"w",stdout);
}
int n,q,t=1,m,k,x,y,z,x2,y2,z2,a[MAX],b[MAX],c[MAX],ans[MAX];
ll res;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
string s[MAX],str[1];
//int e[1001][1001];
//bool e1[1001][1001]; 
string s1,s2,s3;
const int mod = 998244353;
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
vector<vector<int>> g;
void dfs(int v,int prev){
    c[v]=(g[v].size()==1);
    for(auto x:g[v]){
        if(x==prev){
            continue;
        }
        dfs(x,v);
        c[v]+=c[x];
    }
    res+=1-c[v]%2;
}
void solve(){
    cin >> n >> q;
    for(int i=0;i<n-1;i++){
        cin >> a[i] >> b[i];
    }
    for(int i=0;i<q;i++){
        cin >> m;
        g.clear();
        g.resize(n+m+1);
        for(int j=1;j<=m;j++){
            cin >> x;
            g[x].pb(n+j);
            g[n+j].pb(x);
        }
        for(int j=0;j<n-1;j++){
            g[a[j]].pb(b[j]);
            g[b[j]].pb(a[j]);
        }
        for(int j=1;j<=n+m;j++){
            c[j]=0;
        }
        res=n+m-1;
        dfs(1,-1);
        if(c[1]%2){
            cout << -1 << "\n";
        }
        else{
            cout << res-1 << "\n";
        }
    }
}
signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //cin >> t;
    ll cnt1=1;
    while(t--){
        solve();
    }
}

컴파일 시 표준 에러 (stderr) 메시지

cleaning.cpp: In function 'int main()':
cleaning.cpp:103:8: warning: unused variable 'cnt1' [-Wunused-variable]
  103 |     ll cnt1=1;
      |        ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...