QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#562243 | #180. Animal Companion in Maze | PetroTarnavskyi# | AC ✓ | 85ms | 56268kb | C++20 | 1.6kb | 2024-09-13 16:01:43 | 2024-09-13 16:01:43 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef double db;
const int N = 1 << 18;
set<int> uncomputed[N];
set<PII> s[N];
int col[N];
int from[N], to[N];
int ansForEdge[N];
void f(int i)
{
if (col[i] == 1)
{
cout << "Infinite\n";
exit(0);
}
col[i] = 1;
int u = from[i], v = to[i];
while (!uncomputed[v].empty())
{
auto it = uncomputed[v].begin();
if (*it == (i ^ 1))
it++;
if (it == uncomputed[v].end())
break;
f(*it);
}
auto it = prev(s[v].end());
if (it->S == (i ^ 1))
it--;
ansForEdge[i] = it->F + 1;
col[i] = 2;
uncomputed[u].erase(i);
s[u].insert({ansForEdge[i], i});
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
fill(from, from + 2 * m, -1);
fill(to, to + 2 * m, -1);
FOR(i, 0, m)
{
int u, v, w;
cin >> u >> v >> w;
u--;
v--;
uncomputed[u].insert(2 * i);
from[2 * i] = u;
to[2 * i] = v;
if (w == 2)
{
uncomputed[v].insert(2 * i + 1);
from[2 * i + 1] = v;
to[2 * i + 1] = u;
}
}
FOR(v, 0, n)
{
s[v].insert({0, -1});
}
FOR(v, 0, n)
{
while (!uncomputed[v].empty())
{
f(*uncomputed[v].begin());
}
}
cout << *max_element(ansForEdge, ansForEdge + 2 * m) << "\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 7ms
memory: 32260kb
input:
2 2 1 2 2 1 2 2
output:
Infinite
result:
ok single line: 'Infinite'
Test #2:
score: 0
Accepted
time: 59ms
memory: 44032kb
input:
100000 99999 89699 96762 2 14686 33064 1 59361 58678 1 97303 72987 2 27608 56167 1 2709 58751 2 97188 44066 1 83910 20148 1 98548 95716 1 77379 72035 1 63902 62727 2 13961 28993 2 40194 63930 2 39772 8028 2 67378 91869 2 55853 50932 1 65970 16547 2 86976 77908 1 26350 71286 2 52083 4231 2 73581 3569...
output:
34
result:
ok single line: '34'
Test #3:
score: 0
Accepted
time: 85ms
memory: 54588kb
input:
100000 99999 12620 2210 2 26484 30042 2 75143 77219 2 57609 63533 2 86591 15716 2 76441 41847 2 46832 67857 2 35492 44213 2 58432 3130 2 62898 69782 2 76955 78940 2 62241 56391 2 52736 36409 2 45647 65192 2 61021 69355 2 25214 81763 2 81113 87380 2 27278 26199 2 68710 34853 2 82949 82240 2 26029 585...
output:
99999
result:
ok single line: '99999'
Test #4:
score: 0
Accepted
time: 58ms
memory: 43708kb
input:
100000 99999 90231 36955 2 51929 90231 1 90231 70740 1 90231 53131 1 90231 19252 1 90231 9625 2 86742 90231 2 1573 90231 2 90231 79049 2 90231 42756 2 45168 90231 2 10520 90231 1 90231 62536 2 12218 90231 2 49695 90231 2 90231 68461 1 90231 36681 2 68381 90231 1 90231 26553 1 38689 90231 1 90231 749...
output:
2
result:
ok single line: '2'
Test #5:
score: 0
Accepted
time: 85ms
memory: 46208kb
input:
100000 99999 8253 62872 2 62872 14645 2 64940 62872 2 62872 35921 2 48091 62872 2 36797 62872 2 62872 3993 2 68107 62872 2 74939 62872 2 62872 29610 2 62872 24763 2 89774 62872 2 78642 62872 2 62872 3294 2 78828 62872 2 62872 3161 2 32883 62872 2 62872 21803 2 62872 10636 2 76069 62872 2 62872 88818...
output:
2
result:
ok single line: '2'
Test #6:
score: 0
Accepted
time: 48ms
memory: 43772kb
input:
100000 99999 6748 69696 1 41199 95456 1 10445 1394 2 50681 13849 2 89928 96390 1 5272 63437 2 71788 4084 1 17913 59647 1 35179 58239 2 21816 21355 2 27494 7531 1 28274 55450 2 67637 3779 1 66977 37428 2 97913 48795 2 52447 14836 2 35473 64998 1 40625 15340 2 82402 61208 2 30940 61599 1 31807 74004 1...
output:
32
result:
ok single line: '32'
Test #7:
score: 0
Accepted
time: 74ms
memory: 46132kb
input:
100000 99999 39566 38283 2 9848 76057 2 30296 72907 2 88298 86030 2 7073 83873 2 37869 74079 2 82476 96369 2 50608 86808 2 58064 87157 2 15532 71004 2 2854 57296 2 26817 90345 2 66896 8035 2 87982 38682 2 70043 79117 2 15215 43504 2 2704 7664 2 53052 21927 2 57135 1143 2 21549 21739 2 21975 74322 2 ...
output:
32
result:
ok single line: '32'
Test #8:
score: 0
Accepted
time: 62ms
memory: 43804kb
input:
100000 99999 91777 54394 1 87026 83576 1 9347 93899 2 13130 85562 2 20458 18717 1 79056 25048 2 11847 28026 1 10474 86692 1 91431 80701 2 85056 26919 2 52505 3396 2 67456 28626 1 84832 71225 2 78642 18937 1 19402 50781 1 1120 5311 1 60410 99472 2 47314 71253 1 30955 91941 1 76732 89852 2 24717 89331...
output:
34
result:
ok single line: '34'
Test #9:
score: 0
Accepted
time: 80ms
memory: 46192kb
input:
100000 99999 90667 88733 2 60336 29166 2 81582 63374 2 17975 41259 2 85841 26048 2 72887 49320 2 88238 91125 2 84562 65075 2 68826 69497 2 49876 27535 2 61904 86309 2 22256 69996 2 60097 11175 2 86015 63131 2 44644 74536 2 33623 74764 2 69170 1165 2 11675 22483 2 64418 44917 2 49945 69743 2 64908 11...
output:
47
result:
ok single line: '47'
Test #10:
score: 0
Accepted
time: 56ms
memory: 56268kb
input:
100000 100000 70731 59097 2 50874 29387 2 97348 60881 2 70757 74728 2 57390 67621 2 99576 55766 2 97835 43533 2 38195 54494 2 89109 50097 2 6616 61068 2 91987 99959 2 20608 6587 2 73891 30786 2 27577 31448 2 6065 30662 2 95382 88243 2 86168 65037 2 44511 13835 2 9531 1119 2 91629 50601 2 16236 25863...
output:
Infinite
result:
ok single line: 'Infinite'
Test #11:
score: 0
Accepted
time: 39ms
memory: 51556kb
input:
100000 100000 36646 7055 1 62273 63694 1 93020 95599 1 48340 15668 1 9622 60495 1 20527 11535 1 75330 65369 1 35639 2831 1 87359 53961 1 1507 43919 1 2328 51 1 89697 97857 1 79732 35338 1 64706 82770 1 2261 10003 1 77896 79713 1 31356 97303 1 30829 47603 1 68251 38759 1 66458 84182 1 67693 65796 1 9...
output:
Infinite
result:
ok single line: 'Infinite'
Test #12:
score: 0
Accepted
time: 72ms
memory: 43776kb
input:
100000 100000 91454 92931 1 65604 60034 2 64290 64064 1 17884 960 1 75043 60417 2 76233 7102 2 28182 66827 1 74121 55203 1 79376 82235 2 74227 83768 1 366 40923 1 70007 91462 1 91597 43495 1 79312 76448 2 67357 79794 1 80205 67068 2 785 17629 2 29777 57936 1 92348 91921 2 55720 97190 1 1603 63466 2 ...
output:
36
result:
ok single line: '36'
Test #13:
score: 0
Accepted
time: 26ms
memory: 43560kb
input:
99898 100000 74747 67785 1 36219 46116 2 10325 83055 1 99035 69249 2 1937 79341 1 97376 91913 1 97378 30398 1 7627 72726 2 61106 69052 2 78241 52175 1 30079 41578 1 48563 88235 2 18034 56142 2 73156 50367 2 30466 69980 2 45310 13054 1 26676 36775 2 60675 88929 1 96703 83204 2 19991 11069 2 39651 120...
output:
Infinite
result:
ok single line: 'Infinite'
Test #14:
score: 0
Accepted
time: 26ms
memory: 41568kb
input:
49934 99999 890 38699 1 40450 5581 1 28165 42262 2 3101 41864 1 46476 45344 1 7866 5900 2 15602 14981 2 45993 15328 2 20892 39496 1 43011 7681 2 1992 31570 1 45814 46452 1 9155 31994 2 20923 969 2 12246 37678 2 31621 29506 2 34086 45621 1 40129 38508 1 19191 20440 2 6149 33300 1 25765 13716 2 14740 ...
output:
Infinite
result:
ok single line: 'Infinite'
Test #15:
score: 0
Accepted
time: 29ms
memory: 39972kb
input:
33238 99997 7644 5929 1 10211 15883 2 19108 24825 1 32263 2135 1 4575 21104 2 487 29013 1 26301 19807 2 25148 27026 1 15111 25960 2 31944 11707 2 23116 16575 2 5423 12352 1 17112 30422 1 26198 20987 2 12915 407 1 21373 16142 2 2133 24875 2 8296 17367 2 14962 6017 2 28787 16197 2 30505 10017 1 19756 ...
output:
Infinite
result:
ok single line: 'Infinite'
Test #16:
score: 0
Accepted
time: 23ms
memory: 40272kb
input:
24975 100000 24747 8590 2 14965 11050 2 12285 22482 2 10835 24527 2 20758 15101 1 13525 8924 2 6256 8231 1 2845 6081 2 10054 13693 2 19768 24945 2 15219 9049 2 1147 350 2 23113 18230 2 18808 3711 2 22100 17685 1 12213 18622 2 12301 13344 1 4518 8014 2 9208 11698 1 9897 16603 1 7357 17282 2 1952 1453...
output:
Infinite
result:
ok single line: 'Infinite'
Test #17:
score: 0
Accepted
time: 34ms
memory: 40176kb
input:
19950 99994 5172 4174 1 16050 8736 1 16420 4150 1 10637 5292 1 17512 14416 2 17782 17370 1 39 10471 2 18839 14037 1 3302 14126 1 6586 18642 2 11 7523 2 3885 14414 1 16957 14235 2 2634 14220 2 17326 1146 2 14424 16671 1 5995 6271 1 18750 5679 2 10059 10515 2 10949 15287 1 9973 14594 1 9514 16419 2 17...
output:
Infinite
result:
ok single line: 'Infinite'
Test #18:
score: 0
Accepted
time: 37ms
memory: 40192kb
input:
66559 100000 61353 2591 1 7041 31413 1 43222 14106 1 44858 18278 1 18399 21561 1 43317 4000 1 4382 59324 1 64852 45978 1 47785 61737 1 42514 63379 1 29781 861 1 58157 51809 1 4385 24491 1 53114 51309 1 22558 31934 1 58635 26059 1 38038 59819 1 40922 43209 1 22476 39412 1 45328 58455 1 37627 58482 1 ...
output:
41
result:
ok single line: '41'
Test #19:
score: 0
Accepted
time: 43ms
memory: 37924kb
input:
28585 99997 16119 27731 1 22333 6068 1 20822 10432 1 15884 14370 1 17710 13561 1 15297 4361 1 8665 20711 1 2771 25888 1 2806 9221 1 24265 11368 1 9859 18288 1 17701 22364 1 13339 20533 1 7017 25345 1 21435 504 1 14843 24351 1 1903 5593 1 23510 26491 1 15091 155 1 9530 18529 1 14269 27683 1 2978 2694...
output:
61
result:
ok single line: '61'
Test #20:
score: 0
Accepted
time: 40ms
memory: 37864kb
input:
18215 99998 11811 11619 1 5595 706 1 17145 13799 1 15536 14300 1 9994 17105 1 18088 5766 1 17785 2074 1 8467 13548 1 15639 1167 1 5582 10356 1 1021 1484 1 16266 6425 1 6344 3237 1 13035 9965 1 17438 7994 1 15416 7685 1 7705 310 1 5363 17454 1 4852 5980 1 7236 13078 1 9293 281 1 2543 16746 1 13039 10...
output:
80
result:
ok single line: '80'
Test #21:
score: 0
Accepted
time: 29ms
memory: 41376kb
input:
66655 99999 18475 63753 2 42919 32982 2 35737 8656 2 7472 9495 1 51362 56126 1 52527 28923 1 63005 41111 2 35102 49614 2 10361 48482 2 12053 34833 1 13462 47594 2 4067 54248 2 4460 57271 1 25801 47914 1 43255 10555 1 63325 3464 1 60437 12708 1 34004 28297 1 41815 55114 2 27359 35367 2 29728 40822 2 ...
output:
Infinite
result:
ok single line: 'Infinite'
Test #22:
score: 0
Accepted
time: 32ms
memory: 40672kb
input:
28675 99996 17322 12180 2 16737 4572 1 8952 24634 1 149 26182 2 16305 27641 1 22229 6854 1 22704 2348 1 28135 23093 2 9584 22260 2 10762 25551 1 24659 14705 2 356 25093 1 22191 9857 2 10034 28110 2 7177 10865 2 11338 4315 1 23268 2170 2 10092 14303 1 1908 20617 2 6906 27849 1 5117 6861 1 4740 3333 1...
output:
Infinite
result:
ok single line: 'Infinite'
Test #23:
score: 0
Accepted
time: 32ms
memory: 39412kb
input:
18184 99997 5970 5172 1 2772 14656 1 8162 12977 2 8043 544 1 4995 11142 2 10381 10072 1 16050 3957 1 986 7480 1 10743 6602 2 5699 10231 1 6648 11414 1 8697 293 2 14986 12836 1 6026 6226 1 12420 13305 1 1869 7285 1 13529 6076 2 9249 902 1 8781 1811 1 12791 5420 1 16545 6175 2 9836 16776 1 31 15253 1 ...
output:
Infinite
result:
ok single line: 'Infinite'
Test #24:
score: 0
Accepted
time: 78ms
memory: 45916kb
input:
98481 98567 87105 79676 2 87105 65235 2 42097 72215 2 73578 93805 2 73828 89918 2 14301 81648 2 87734 73828 2 76679 57273 2 14728 57273 2 3375 19241 2 48098 73578 2 95042 87105 2 57273 48858 2 14301 46594 2 84872 47572 2 39935 34339 2 60822 87105 2 57273 75830 2 73828 77737 2 69471 57273 2 57840 579...
output:
30
result:
ok single line: '30'
Test #25:
score: 0
Accepted
time: 79ms
memory: 46056kb
input:
97848 97961 66772 48185 2 43089 33293 2 77597 2395 2 84766 85921 2 64212 58075 2 66772 80738 2 27672 43089 2 27945 43089 2 84115 85921 2 77597 55100 2 85921 12800 2 85921 63349 2 58088 85921 2 31553 85921 2 28423 38273 2 53326 43089 2 77597 37155 2 73201 64212 2 28423 23845 2 64212 6302 2 40451 4308...
output:
24
result:
ok single line: '24'
Test #26:
score: 0
Accepted
time: 58ms
memory: 45512kb
input:
93969 94056 12062 28190 2 8702 22962 2 87225 79490 2 1485 22962 2 29003 28190 2 22962 67603 2 28190 11962 2 22962 23556 2 69097 19395 2 22962 71011 2 19395 70753 2 54846 44187 2 52733 19395 2 22962 70875 2 71666 22962 2 32107 88801 2 62965 5997 2 22962 59271 2 32107 17434 2 32107 63902 2 32107 39445...
output:
15
result:
ok single line: '15'
Test #27:
score: 0
Accepted
time: 51ms
memory: 46784kb
input:
66668 100000 27590 55723 1 21111 27026 2 18344 1860 1 50633 49921 2 104 28058 1 53378 64362 1 38615 50533 1 2941 64131 1 65507 61071 2 52042 65006 1 58014 56056 1 22619 61051 2 7800 43700 1 24211 716 2 7832 17638 2 9861 38410 1 61181 59065 1 42966 22559 1 53301 14952 1 44737 58398 1 29162 24599 2 65...
output:
66667
result:
ok single line: '66667'
Test #28:
score: 0
Accepted
time: 62ms
memory: 41532kb
input:
51391 99971 27678 45009 1 27988 47205 1 13892 22513 2 14495 22962 1 15397 45289 1 37392 13350 2 46303 37118 1 19591 50616 2 11608 25740 1 40081 28869 2 43816 10 2 30694 13464 2 30981 18642 2 38526 15347 1 7370 33987 1 29743 24161 2 41420 2050 2 3727 24011 2 18902 14732 1 11299 38431 2 50370 5683 1 1...
output:
684
result:
ok single line: '684'
Test #29:
score: 0
Accepted
time: 64ms
memory: 41404kb
input:
51055 99999 4557 11215 1 39051 21001 2 26753 26948 2 451 41641 1 39194 15156 2 14825 3130 1 3940 1121 2 8504 15515 1 48017 12448 2 27752 25610 2 27244 30164 1 50556 12383 1 49639 997 2 18965 7072 2 39203 4992 2 6613 345 2 40269 2089 2 11196 16899 2 34198 3658 2 44208 22484 2 28173 33250 1 39631 4925...
output:
1587
result:
ok single line: '1587'
Test #30:
score: 0
Accepted
time: 64ms
memory: 41160kb
input:
50430 99997 31925 4648 1 20393 48017 1 4469 36241 1 16521 15572 2 15774 45270 2 6388 40107 2 16039 25814 1 46420 49646 2 24317 26779 1 21194 6302 2 11808 14940 1 35484 850 2 40166 34984 2 48843 40952 1 32017 15544 1 25703 40388 1 22673 45945 1 26231 43762 1 37714 26094 2 6274 44334 1 11321 14905 1 3...
output:
2174
result:
ok single line: '2174'
Test #31:
score: 0
Accepted
time: 54ms
memory: 41208kb
input:
50337 99948 2787 11413 2 10845 41317 1 41071 736 2 4122 14360 1 14433 27977 1 37744 45488 2 34953 2642 2 41963 2441 1 46169 34278 1 46097 45458 1 16881 9622 2 28181 28096 1 28006 46058 2 49392 43758 1 40340 5256 2 34724 45371 1 36039 24607 1 27615 15624 1 5226 38577 2 29730 5881 2 43488 24072 1 5015...
output:
2772
result:
ok single line: '2772'
Test #32:
score: 0
Accepted
time: 56ms
memory: 41664kb
input:
50556 99991 19057 13413 1 22702 9009 2 18588 31425 2 28690 1877 1 21747 44897 1 12149 19492 2 924 41118 1 34485 36093 1 2744 35416 1 46749 230 2 42629 15906 2 23871 12285 2 7713 48093 2 37333 4245 2 18475 12757 1 32219 34138 1 27333 40034 2 6076 24611 2 36821 32085 1 30047 32465 2 1195 19660 2 5500 ...
output:
3454
result:
ok single line: '3454'
Test #33:
score: 0
Accepted
time: 63ms
memory: 41212kb
input:
49682 99955 4028 12589 1 25675 22597 2 44418 27513 2 41763 34309 2 25832 9434 2 14064 23225 2 38338 24956 1 5259 22366 1 24975 33056 1 13090 44149 1 26394 41966 1 19979 29148 2 42408 19377 2 29861 39413 2 39196 41614 2 10085 15168 2 3192 47485 2 12612 4149 1 49268 2046 1 30488 37138 2 5268 41071 1 1...
output:
4621
result:
ok single line: '4621'
Test #34:
score: 0
Accepted
time: 65ms
memory: 41244kb
input:
50076 99989 34624 20190 1 21959 15266 2 31050 13643 2 30250 19708 2 404 30090 2 41115 22219 2 29493 4218 2 38790 17190 1 1138 4911 2 43690 38032 2 17973 44995 2 11745 50060 1 28075 43784 2 45305 18120 2 46545 34520 2 9133 43074 1 25921 17032 2 36092 32049 2 16659 48709 1 41972 17098 2 30405 24905 1 ...
output:
4875
result:
ok single line: '4875'
Test #35:
score: 0
Accepted
time: 58ms
memory: 41852kb
input:
51303 99932 14193 32378 2 46316 28589 1 33057 20796 2 37903 13365 2 10077 29449 1 31725 34265 2 16258 42050 1 49568 42505 2 22205 28868 2 29802 4575 2 6230 3434 2 4972 620 1 33228 43900 1 22679 38365 1 27352 34359 2 3060 31621 1 901 31084 1 27738 43105 1 2243 41422 2 20241 41013 1 8636 22880 2 48059...
output:
5186
result:
ok single line: '5186'
Test #36:
score: 0
Accepted
time: 61ms
memory: 41216kb
input:
49963 99939 258 1397 2 39826 49463 1 2388 7039 2 47785 42516 1 40708 44969 1 38580 38556 2 4402 35261 1 27728 8396 1 36191 32233 1 6806 49132 1 20976 4803 1 6969 16409 2 36607 18795 1 11941 29565 2 17686 12242 2 29618 12615 2 18746 10977 2 35080 17634 1 18228 5145 2 14169 11843 2 20789 38440 2 17899...
output:
5716
result:
ok single line: '5716'
Test #37:
score: 0
Accepted
time: 61ms
memory: 41812kb
input:
50439 99848 31369 39543 2 31393 28162 1 11367 43219 1 29866 38335 1 15577 8174 2 47928 35013 1 14663 20797 2 4577 24285 1 38737 18166 2 19792 34573 2 9606 41963 1 22224 28237 1 31500 40367 1 9669 35513 1 22460 34132 1 44007 35801 1 8334 20158 2 27467 29848 2 4548 5790 1 33558 43057 1 29228 5941 1 78...
output:
6498
result:
ok single line: '6498'