QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#811263 | #9866. Extracting Weights | ericmegalovania | WA | 1ms | 3972kb | C++20 | 2.4kb | 2024-12-12 17:11:06 | 2024-12-12 17:11:07 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ONLINE
#ifndef ONLINE
char DEBUG_BUFFER[1000];
#define debug(...) {sprintf(DEBUG_BUFFER,##__VA_ARGS__);\
cerr<<"\033[1;36m"<<DEBUG_BUFFER<<"\033[0;2m"<<"\033[0m";}
#else
#define debug(...) ;
#endif
using LL=long long;
using PII=pair<int,int>;
#define all(x) (x).begin(),(x).end()
#define allr(x) (x).rbegin(),(x).rend()
inline int read(){static int x; scanf("%d",&x); return x;}
inline LL readLL(){static LL x; scanf("%lld",&x); return x;}
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());
#define N 250
using Node=bitset<N>;
class LB{ //linear-basis
private:
array<Node,N>a;
public:
LB(){init();}
void init(){
for(int i=0;i<N;i++){
a[i].reset();
}
}
bool insert(Node x){
for(int i=N-1;i>=0 && x.any();i--){
if(!(x[i])) continue;
if(!a[i].any()){
a[i]=x;
return 1;
}
x^=a[i];
}
return 0;
}
};
int n,k,cnt=0;
vector<int>e[N];
LB lb;
Node A[N],node;
LL B[N]={0};
PII qry[N];
void dfs(int s,int u,int fa,int nw){
node[u]=1;
debug("s=%d u=%d nw=%d\n",s+1,u+1,nw);
if(nw==k){
if(s<u && lb.insert(node)){
A[cnt]=node;
qry[cnt]={s+1,u+1};
++cnt;
}
goto RET;
}
for(auto v:e[u]){
if(v==fa) continue;
dfs(s,v,u,nw+1);
}
RET:node[u]=0;
}
int main(){
lb.init(),node.reset();
scanf("%d%d",&n,&k);
for(int i=1,u,v;i<n;i++){
cin>>u>>v;
--u,--v;
e[u].push_back(v);
e[v].push_back(u);
}
node[0]=1;
lb.insert(node);
A[cnt++]=node;
node[0]=0;
for(int i=0;i<n;i++){
dfs(i,i,0,0);
}
debug("cnt=%d\n",cnt);
if(cnt!=n){
assert(cnt<n);
printf("NO\n");
// if(n>100) cout<<cnt;
fflush(stdout);
return 0;
}
printf("YES\n? %d",n-1);
for(int i=1;i<n;i++){
printf(" %d %d",qry[i].first,qry[i].second);
}
cout<<endl;
for(int i=1;i<n;i++){
scanf("%lld",&B[i]);
}
for(int i=0;i<n;i++){
for(int j=i;j<n;j++){
if(A[j][i]){
swap(A[i],A[j]);
swap(B[i],B[j]);
break;
}
}
for(int j=0;j<n;j++){
if(i==j) continue;
if(A[j][i]){
A[j]^=A[i];
B[j]^=B[i];
}
}
}
printf("!");
for(int i=1;i<n;i++){
printf(" %lld",B[i]);
}
cout<<endl;
return 0;
}
/* stuff you should look for
* int overflow, array bounds
* special cases (n=1?)
* do smth instead of nothing and stay organized
* WRITE STUFF DOWN
* DON'T GET STUCK ON ONE APPROACH
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3972kb
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: 3760kb
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: 0ms
memory: 3900kb
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: 3960kb
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 2 195 2 197 3 162 3 134 4 72 4 16 5 140 5 240 6 207 6 156 7 99 7 16 8 106 8 213 9 110 9 56 10 81 10 126 11 30 11 128 12 41 12 107 13 174 13 218 14 235 14 121 15 242 15 223 17 177 17 161 18 173 18 197 19 171 19 181 20 62 20 205 21 249 21 27 22 218 22 102 23 153 23 182 24 92 24 78 25 1...
result:
ok OK 249 numbers
Test #5:
score: 0
Accepted
time: 0ms
memory: 3908kb
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 2 7 2 168 3 237 4 92 4 93 5 56 5 166 6 159 6 230 8 214 8 184 9 106 10 103 10 93 11 155 12 179 12 100 13 194 13 208 14 184 14 219 15 112 15 148 15 137 16 86 16 70 17 101 17 225 18 56 19 68 19 158 20 217 20 160 20 119 21 131 22 142 23 140 23 245 24 230 24 117 25 139 25 242 26 56 26...
result:
ok OK 249 numbers
Test #6:
score: -100
Wrong Answer
time: 0ms
memory: 3844kb
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:
NO
result:
wrong answer Expected "YES", but found "NO"