QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#143783 | #6745. Delete the Tree | qzzyq | WA | 1ms | 3916kb | C++14 | 2.1kb | 2023-08-21 14:43:25 | 2023-08-21 14:43:36 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define maxn 505
#define put() putchar('\n')
#define Tp template<typename Ty>
#define Ts template<typename Ty,typename... Ar>
using namespace std;
inline void read(int &x){
int f=1;x=0;char c=getchar();
while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
while (c>='0'&&c<='9') {x=x*10+c-'0';c=getchar();}
x*=f;
}
namespace Debug{
Tp void _debug(char* f,Ty t){cerr<<f<<'='<<t<<endl;}
Ts void _debug(char* f,Ty x,Ar... y){while(*f!=',') cerr<<*f++;cerr<<'='<<x<<",";_debug(f+1,y...);}
Tp ostream& operator<<(ostream& os,vector<Ty>& V){os<<"[";for(auto& vv:V) os<<vv<<",";os<<"]";return os;}
#define gdb(...) _debug((char*)#__VA_ARGS__,__VA_ARGS__)
}using namespace Debug;
#define fi first
#define se second
#define mk make_pair
const int mod=1e9+7;
inline int power(int x,int y=mod-2) {
int sum=1;
while (y) {
if (y&1) sum=sum*x%mod;
x=x*x%mod;y>>=1;
}
return sum;
}
int n;
vector<int> to[maxn];
int dfn[maxn],times;
vector<int>O[105];
signed main(void){
int i,j,x,y;
read(n);
for (i=1;i<n;i++) {
read(x),read(y);
to[x].push_back(y);
to[y].push_back(x);
}
int cnt=n;
for (j=1;j<=20&&cnt;j++) {
for (i=1;i<=n;i++) if (!dfn[i]) {
int nums=0,tot=0;
for (auto y:to[i]) nums+=(dfn[y]==0),tot+=(dfn[y]==j);
// gdb(j,i,nums,tot);
if (nums<=1&&!tot) dfn[i]=j,O[j].push_back(i),cnt--;
}
// gdb(j,cnt);
for (i=1;i<=n;i++) if (!dfn[i]) {
int nums=0,tot=0,tmp1=0,tmp2=0,tmp3=0;
for (auto y:to[i]) {
if (dfn[y]==0) {
nums++;
if (!tmp1) tmp1=y;
else if (!tmp2) tmp2=y;
else if (!tmp3) tmp3=y;
}
tot+=(dfn[y]==j);
}
if (nums==2&&!tot) {
dfn[i]=j;O[j].push_back(i);cnt--;
to[tmp1].push_back(tmp2);
to[tmp2].push_back(tmp1);
}
else if (nums==3&&!tot) {
dfn[i]=j;O[j].push_back(i);cnt--;
to[tmp1].push_back(tmp3);
to[tmp3].push_back(tmp2);
to[tmp2].push_back(tmp1);
}
}
}
int k=j-1;
for (printf("%d\n",k),j=1;j<=k;j++) {
printf("%d ",O[j].size());
for (auto x:O[j]) printf("%d ",x);put();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3828kb
input:
5 1 2 1 3 1 4 4 5
output:
3 3 2 3 5 1 1 1 4
result:
ok
Test #2:
score: 0
Accepted
time: 1ms
memory: 3616kb
input:
500 183 443 32 443 334 443 254 443 331 443 348 443 54 443 430 443 275 443 410 443 360 443 443 468 140 443 179 443 93 443 327 443 128 443 365 443 122 443 43 443 46 443 399 443 398 443 269 443 130 443 227 443 412 443 61 443 295 443 98 443 30 443 197 443 397 443 95 443 192 443 266 443 48 443 310 443 28...
output:
2 499 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 10...
result:
ok
Test #3:
score: 0
Accepted
time: 1ms
memory: 3916kb
input:
500 80 180 80 254 1 180 80 337 180 323 80 248 180 205 80 189 180 480 80 330 180 454 80 498 142 180 80 193 180 346 80 89 180 389 80 125 180 232 80 93 180 228 80 327 180 357 80 417 180 362 80 278 180 316 80 312 163 180 80 310 176 180 80 463 180 210 80 478 180 294 80 185 124 180 80 143 180 339 80 253 1...
output:
3 498 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 1...
result:
ok
Test #4:
score: 0
Accepted
time: 0ms
memory: 3688kb
input:
500 387 488 301 488 301 413 13 413 13 265 176 265 176 398 74 398 74 241 241 415 386 415 386 448 210 448 210 285 147 285 147 264 19 264 19 314 314 335 54 335 54 261 261 484 425 484 350 425 156 350 156 164 164 420 8 420 8 309 230 309 230 441 408 441 183 408 183 410 204 410 204 318 151 318 151 328 328 ...
output:
10 222 232 387 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 28 29 31 32 33 34 35 37 38 39 41 42 44 46 47 48 49 50 51 53 54 55 56 57 58 60 61 63 64 65 66 67 68 69 70 72 73 74 75 77 78 80 81 82 84 85 87 89 90 91 92 95 96 97 98 100 101 104 105 106 107 108 110 111 113 114 117 119...
result:
ok
Test #5:
score: -100
Wrong Answer
time: 0ms
memory: 3916kb
input:
500 147 209 104 147 13 209 209 466 104 485 17 104 13 214 13 179 151 466 176 466 130 485 286 485 17 359 17 178 214 486 55 214 179 350 179 327 151 167 151 498 146 176 102 176 99 130 130 232 286 294 286 389 56 359 330 359 178 488 178 441 440 486 210 486 55 157 55 458 237 350 350 352 327 371 317 327 167...
output:
7 315 3 5 6 7 9 10 18 19 20 22 24 25 27 29 31 32 33 34 35 37 38 39 41 44 47 48 49 51 53 57 58 59 60 61 62 63 64 66 67 70 71 73 81 85 86 87 90 91 94 95 96 100 107 112 113 116 120 123 128 129 132 133 138 139 140 141 142 143 149 153 155 156 158 160 161 163 164 166 168 169 170 173 174 180 181 182 184 18...
result:
wrong answer