QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#813423 | #9875. Don't Detect Cycle | ucup-team1004# | WA | 19ms | 5000kb | C++14 | 1.2kb | 2024-12-14 08:49:14 | 2024-12-14 08:49:15 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=4e4+10;
vector<int> v1,v2;
vector<pair<int,int>> to[N];
int cnt,flag,dfn[N],low[N],T,n,m,p[N],a[N],b[N];
void dfs(int x,int fa)
{
dfn[x]=low[x]=++cnt;
for(auto k:to[x])
if(k.first!=fa)
{
int y=k.first;
if(!dfn[y])
{
dfs(y,x),low[x]=min(low[x],low[y]);
if(dfn[y]==low[y])
flag=1,v1.push_back(k.second),p[k.second]=1;
}
else low[x]=min(low[x],dfn[y]);
}
}
int main()
{
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++)
scanf("%d%d",&a[i],&b[i]),p[i]=0;
while(1)
{
for(int i=1;i<=n;i++) dfn[i]=low[i]=0,to[i].clear();
cnt=flag=0;
for(int i=1;i<=m;i++)
if(!p[i]) to[a[i]].push_back({b[i],i}),to[b[i]].push_back({a[i],i});
for(int i=1;i<=n;i++) if(!dfn[i]) dfs(i,0);
if(!flag)
{
for(int i=1;i<=m;i++)
if(!p[i]&&(int)max(to[a[i]].size(),to[b[i]].size())<=2)
{
p[i]=1,v2.push_back(i);
flag=1;
break;
}
}
if(!flag) break;
}
if((int)(v1.size()+v2.size())<m) {puts("-1");continue;}
reverse(v2.begin(),v2.end());
for(int x:v1) printf("%d ",x);
for(int x:v2) printf("%d ",x);
puts(""),v1.clear(),v2.clear();
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 4824kb
input:
1 4 4 1 2 2 3 3 4 4 2
output:
1 3 4 2
result:
ok Correct
Test #2:
score: 0
Accepted
time: 1ms
memory: 4824kb
input:
4 4 5 1 2 2 3 3 4 3 1 1 4 5 3 1 2 2 3 3 4 9 10 3 5 1 8 5 8 4 9 6 7 7 9 1 2 1 4 2 4 4 6 8 10 1 4 3 8 2 5 3 4 1 5 5 8 2 8 5 7 4 5 3 7
output:
-1 3 2 1 1 3 2 6 4 10 9 8 7 5 -1
result:
ok Correct
Test #3:
score: 0
Accepted
time: 19ms
memory: 5000kb
input:
50 3214 2907 970 1929 2860 3033 1322 2296 931 1192 861 2505 831 2469 231 2549 1 2306 1765 1842 999 3171 177 2007 1798 1894 827 3180 673 1738 1163 1573 2213 2781 2766 3200 1663 2197 1797 2281 315 2637 442 2689 558 2874 1520 2591 651 1923 1133 2920 1747 2412 1104 1528 313 2487 632 3124 660 2182 1581 2...
output:
215 1955 1454 1326 925 1022 1059 2188 1826 392 887 1521 846 1647 1327 329 155 136 441 1274 191 2201 1115 2196 892 971 23 124 2114 842 1835 103 991 384 1621 123 367 79 1004 184 696 458 2279 618 1918 866 1079 1007 475 1054 1128 1001 28 379 657 1446 2518 2061 682 1006 1093 2342 66 2735 53 2679 476 287 ...
result:
ok Correct
Test #4:
score: 0
Accepted
time: 1ms
memory: 4744kb
input:
48 732 104 388 425 176 558 7 695 504 507 163 705 204 456 139 432 104 716 535 582 254 682 70 278 77 385 600 680 373 564 197 653 335 569 81 579 339 604 407 580 253 383 480 549 145 308 52 373 426 525 268 359 408 595 47 397 479 569 268 403 477 663 434 660 330 343 56 692 376 450 200 553 299 713 114 584 1...
output:
3 48 101 57 66 72 53 27 63 14 23 98 33 71 79 11 12 17 69 97 99 52 43 8 58 38 28 16 42 37 94 56 103 55 75 73 34 74 82 47 54 7 81 44 22 64 5 49 2 92 59 102 50 80 15 93 35 88 77 6 83 62 60 20 10 40 100 1 51 87 104 25 29 95 70 61 41 36 78 32 91 65 18 84 39 85 76 19 26 89 96 24 31 46 67 90 30 21 4 9 68 4...
result:
ok Correct
Test #5:
score: 0
Accepted
time: 2ms
memory: 4904kb
input:
24 3635 2454 724 2161 994 3233 30 278 2047 3627 693 1048 112 2609 9 1552 889 946 987 2538 923 1911 53 1198 2429 3200 1338 3544 504 2644 1116 3446 815 877 245 3601 2177 3180 212 1638 1140 3241 159 2455 2447 2460 957 1585 980 2338 1254 3014 382 3596 510 595 1408 2300 2053 2276 2177 3415 1051 3353 136 ...
output:
794 95 2192 978 42 1318 440 283 2354 1320 1465 469 1438 2145 1773 2236 2147 338 1642 1611 901 1481 1494 1426 422 1793 1110 1059 1937 2161 2451 2368 96 914 1155 555 1158 344 1280 873 591 859 728 1298 171 2314 8 1290 16 192 52 1631 1237 1531 1583 1873 1034 1192 2193 1674 1535 73 93 2070 1503 15 351 55...
result:
ok Correct
Test #6:
score: 0
Accepted
time: 4ms
memory: 4944kb
input:
56 2367 1768 132 2148 1280 2214 473 2270 78 2126 374 2080 777 1617 74 152 46 125 36 1136 1340 2010 1536 1801 291 619 610 1567 1688 2303 1005 2308 1101 1988 1695 2257 1056 1405 1134 1579 1819 2281 1281 1952 2065 2102 1984 2353 215 1994 984 2258 1916 2059 1128 2198 966 1048 965 1424 866 932 227 543 33...
output:
1049 1609 1274 624 297 1296 698 652 1268 241 1619 707 1110 377 239 1008 1319 492 1154 649 384 655 1018 44 154 42 563 972 1538 546 218 69 483 277 742 499 783 978 86 1439 1184 1348 904 1186 429 1745 17 566 149 1223 1370 215 682 778 1471 291 422 801 1353 1441 203 788 837 305 416 152 683 389 475 1606 11...
result:
ok Correct
Test #7:
score: -100
Wrong Answer
time: 12ms
memory: 4908kb
input:
56 1804 2031 215 520 41 228 505 1449 1202 1467 175 474 583 1684 127 1013 11 1132 251 1009 1333 1516 22 633 168 1160 866 1584 1501 1510 425 1494 563 1764 1341 1646 76 114 541 943 163 166 103 184 455 1225 708 1649 836 1551 551 1381 570 1509 125 221 371 1117 436 1012 392 732 76 379 1040 1359 119 1405 1...
output:
-1 432 16 486 1632 33 1909 515 508 1914 961 581 190 1383 255 186 1942 92 385 1564 374 476 260 1604 41 1543 864 1159 630 1738 25 1387 153 1222 398 2023 639 121 537 839 1250 1692 435 95 645 3 743 768 53 972 1766 431 74 680 29 90 455 910 294 1196 106 1385 789 1779 178 313 179 277 965 1268 1327 935 780 ...
result:
wrong answer Integer 432 violates the range [-1, 18]