QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#804687#9866. Extracting Weightsucup-team1134#WA 2ms4096kbC++235.3kb2024-12-08 02:17:592024-12-08 02:17:59

Judging History

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

  • [2024-12-08 02:17:59]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:4096kb
  • [2024-12-08 02:17:59]
  • 提交

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];
vi AA;

void DFS(int u,int p){
    if(u) AA.pb(u);
    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:AA){
            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: 0ms
memory: 3616kb

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: 0ms
memory: 3828kb

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: 3568kb

input:

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

output:

NO

result:

ok Correct

Test #4:

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

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 1 233 233 176 176 80 80 186 186 25 25 38 38 91 91 213 213 8 8 106 106 139 139 163 163 134 134 3 3 162 162 73 73 90 90 232 232 48 48 29 29 244 244 142 142 145 145 40 40 28 28 147 147 216 216 120 120 165 165 205 205 20 20 62 62 50 50 127 127 210 210 36 36 226 226 41 41 12 12 107 107 77 77 47...

result:

ok OK 249 numbers

Test #5:

score: 0
Accepted
time: 2ms
memory: 3856kb

input:

250 1
159 6
156 104
218 66
172 38
158 142
37 143
171 240
53 204
139 103
152 177
213 231
91 93
75 77
39 125
239 28
196 237
185 209
40 219
43 114
129 222
162 247
140 23
48 35
184 215
186 155
58 178
178 98
82 91
238 164
33 54
127 165
60 151
2 7
160 223
189 247
50 209
189 205
81 49
237 180
88 156
225 20...

output:

YES
? 249 1 72 1 60 60 151 151 148 148 233 148 15 15 112 112 99 99 37 37 143 143 84 84 76 76 196 196 237 237 180 180 169 169 83 83 77 77 75 77 67 67 85 85 139 139 103 103 10 10 93 93 91 91 82 82 128 128 243 243 154 154 168 168 2 2 7 243 181 181 175 175 130 130 118 118 61 61 109 109 232 109 81 81 49 ...

result:

ok OK 249 numbers

Test #6:

score: 0
Accepted
time: 2ms
memory: 4096kb

input:

250 2
138 236
154 181
103 227
74 169
248 123
25 69
26 157
250 216
164 75
89 215
93 43
76 56
56 153
88 139
121 72
130 228
231 198
224 75
238 235
66 8
119 77
129 204
125 30
204 165
113 60
156 14
226 192
54 201
61 70
59 62
11 233
60 44
240 177
79 152
88 13
137 26
186 133
94 134
180 246
167 126
61 79
10...

output:

YES
? 249 1 24 232 224 232 50 224 50 232 101 1 120 24 75 224 164 75 231 164 198 231 174 198 146 174 22 146 215 22 89 146 59 22 62 59 177 62 240 177 196 240 119 196 77 196 135 119 222 135 227 222 103 135 23 222 200 23 17 200 64 17 151 64 4 151 166 4 106 166 114 106 162 166 40 106 55 40 68 55 176 68 1...

result:

ok OK 249 numbers

Test #7:

score: 0
Accepted
time: 0ms
memory: 3564kb

input:

250 3
208 175
120 43
87 33
248 90
78 198
220 229
177 17
239 236
142 187
48 35
233 214
53 14
12 184
126 227
77 113
202 41
152 12
108 19
69 136
168 163
176 57
179 110
159 211
28 103
102 137
180 156
165 101
87 150
89 132
38 151
242 49
81 165
127 185
41 127
115 215
11 29
216 92
215 34
145 75
141 45
235 ...

output:

NO

result:

ok Correct

Test #8:

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

input:

250 4
116 188
148 118
200 249
230 192
208 143
189 157
22 2
23 212
140 107
67 215
46 18
38 111
135 129
22 19
210 158
224 171
31 10
36 113
48 238
146 225
184 147
52 85
189 191
247 244
68 6
234 70
45 204
221 186
100 172
192 173
108 7
217 87
56 80
63 117
193 47
153 181
52 65
166 102
133 121
151 117
243 ...

output:

NO

result:

wrong answer Expected "YES", but found "NO"