QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#804680#9866. Extracting Weightsucup-team1134#WA 2ms3748kbC++235.3kb2024-12-08 02:13:532024-12-08 02:13:53

Judging History

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

  • [2024-12-08 02:13:53]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3748kb
  • [2024-12-08 02:13:53]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pair<int,int>>
#define vll vector<pair<ll,ll>>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define vvii vector<vector<pair<int,int>>>
#define vvll vector<vector<pair<ll,ll>>>
#define vst vector<string>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define mkunique(x) sort(all(x));(x).erase(unique(all(x)),(x).end())
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=300005,INF=15<<26;

vi G[MAX];
int de[MAX],par[MAX];

void DFS(int u,int p){
    par[u]=p;
    for(int to:G[u]){
        if(to==p) continue;
        de[to]=de[u]+1;
        DFS(to,u);
    }
}

void solve(int u,int p,vii &ask){
    if(de[u]>=2) ask.pb(mp(par[par[u]],u));
    for(int to:G[u]){
        if(to==p) continue;
        solve(to,u,ask);
    }
}

typedef vector<int> vec;
typedef vector<vec> mat;

vec gauss_jordan(const mat& A,const vec &b){
    int n=A.size();
    mat B(n,vec(n+1));
    
    for(int i=0;i<n;i++) for(int j=0;j<n;j++) B[i][j]=A[i][j];
    
    for(int i=0;i<n;i++) B[i][n]=b[i];
    
    int rank=0;
    
    for(int j=0;j<n;j++){
        int pivot=-1;
        
        for(int i=rank;i<n;i++){
            if(B[i][j]){
                pivot=i;
                break;
            }
        }
        
        if(pivot==-1) continue;
        
        swap(B[pivot],B[rank]);
        
        for(int i=0;i<n;i++){
            if(i!=rank){
                if(B[i][j]){
                    for(int k=0;k<=n;k++) B[i][k]^=B[rank][k];
                }
            }
        }
        
        rank++;
    }
    
    bool ok=true;
    
    for(int i=rank;i<n;i++){
        if(B[i][n]) ok=false;
    }
    
    if(!ok) return vec();
    
    vec x(n);
    
    for(int i=0;i<rank;i++) x[i]=B[i][n];
    return x;
}

int main(){
    
    int N,K;cin>>N>>K;
    for(int i=0;i<N-1;i++){
        int a,b;cin>>a>>b;a--;b--;
        G[a].pb(b);
        G[b].pb(a);
    }
    DFS(0,-1);
    
    if(K==1){
        cout<<"YES"<<endl;
        vii ask;
        for(int i=1;i<N;i++){
            ask.pb(mp(par[i],i));
        }
        cout<<"? "<<si(ask);
        for(auto [a,b]:ask) cout<<" "<<a+1<<" "<<b+1;
        cout<<endl;
        vi res;
        for(int i=0;i<si(ask);i++){
            int x;cin>>x;
            res.pb(x);
        }
        vi ans(N);
        for(int i=0;i<si(ask);i++){
            ans[ask[i].se]=ans[ask[i].fi]^res[i];
        }
        cout<<"!";
        for(int i=1;i<N;i++){
            cout<<" "<<ans[i];
        }
        cout<<endl;
    }else if(K>=3){
        cout<<"NO"<<endl;
    }else{
        int tane=-1;
        for(int i=0;i<N;i++){
            if(de[i]==2&&si(G[i])>=3){
                tane=i;
            }
        }
        if(tane==-1){
            cout<<"NO"<<endl;
        }else{
            cout<<"YES"<<endl;
            vii ask;
            vi X;
            for(int to:G[tane]){
                if(to==par[tane]) continue;
                X.pb(to);
            }
            ask.pb(mp(0,tane));
            ask.pb(mp(par[tane],X[0]));
            ask.pb(mp(par[tane],X[1]));
            ask.pb(mp(X[0],X[1]));
            int Z=par[tane];
            for(int to:G[Z]){
                if(to==0||to==tane) continue;
                solve(to,Z,ask);
            }
            for(int to:G[0]){
                if(to==Z) continue;
                ask.pb(mp(Z,to));
                solve(to,0,ask);
            }
            for(int to:G[tane]){
                if(to==X[0]||to==X[1]||to==par[tane]) continue;
                solve(to,tane,ask);
            }
            for(int to:G[X[0]]){
                if(to==tane) continue;
                solve(to,X[0],ask);
            }
            for(int to:G[X[1]]){
                if(to==tane) continue;
                solve(to,X[1],ask);
            }
            cout<<"? "<<si(ask);
            for(auto [a,b]:ask) cout<<" "<<a+1<<" "<<b+1;
            cout<<endl;
            vi res;
            for(int i=0;i<si(ask);i++){
                int x;cin>>x;
                res.pb(x);
            }
            mat A(si(ask),vi(N-1));
            for(int i=0;i<si(ask);i++){
                int a=ask[i].fi,b=ask[i].se;
                if(de[b]>=2&&par[par[b]]==a){
                    int x=a,y=par[b],z=b;
                    if(x) A[i][x-1]=1;
                    if(y) A[i][y-1]=1;
                    if(z) A[i][z-1]=1;
                }else{
                    int x=a,y=b,z=par[a];
                    assert(par[b]==z);
                    if(x) A[i][x-1]=1;
                    if(y) A[i][y-1]=1;
                    if(z) A[i][z-1]=1;
                }
            }
            cout<<"!";
            auto ress=gauss_jordan(A,res);
            for(int i=0;i<N-1;i++) cout<<" "<<ress[i];
            cout<<endl;
        }
    }
}



详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3548kb

input:

4 1
1 2
2 3
2 4
1 3 2

output:

YES
? 3 1 2 2 3 2 4
! 1 2 3

result:

ok OK 3 numbers

Test #2:

score: 0
Accepted
time: 1ms
memory: 3600kb

input:

5 2
1 2
2 3
3 4
3 5
1 2 3 4

output:

YES
? 4 1 3 2 4 2 5 4 5
! 4 5 3 2

result:

ok OK 4 numbers

Test #3:

score: 0
Accepted
time: 1ms
memory: 3748kb

input:

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

output:

NO

result:

ok Correct

Test #4:

score: -100
Wrong Answer
time: 2ms
memory: 3612kb

input:

250 1
108 84
37 129
33 68
131 135
26 173
186 25
35 104
78 123
52 115
239 44
166 149
127 210
185 212
246 64
249 143
137 101
82 209
244 29
15 242
20 62
243 151
81 10
42 159
65 71
71 105
166 192
214 225
97 87
86 208
43 60
235 54
77 107
28 147
195 2
45 153
104 180
63 250
205 165
220 206
24 92
12 41
233 ...

output:

YES
? 249 195 2 134 3 16 4 140 5 156 6 99 7 213 8 110 9 126 10 30 11 41 12 218 13 235 14 242 15 7 16 161 17 197 18 181 19 205 20 27 21 102 22 182 23 92 24 186 25 173 26 246 27 40 28 48 29 96 30 172 31 175 32 157 33 178 34 53 35 210 36 128 37 25 38 152 39 145 40 226 41 223 42 60 43 239 44 153 45 237 ...

result:

wrong answer Wrong answer in node 2, expected "606574760", but found "1029923445".