QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#258761 | #1987. Emails | Stypox | AC ✓ | 44ms | 10212kb | C++23 | 1.6kb | 2023-11-20 06:18:02 | 2023-11-20 06:18:03 |
Judging History
answer
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;
#define int int64_t
#define float long double
#ifdef DEBUG
template<class A,class B>ostream&operator<<(ostream&o,const pair<A,B>&p){cerr<<"("<<p.first<<", "<<p.second<<")";return o;}
template<class T,typename=typename enable_if<!is_same<T, string>::value,decltype(*begin(declval<T>()))>::type>ostream&operator<<(ostream&o,const T&v){cerr<<"[";for(auto it=v.begin();it!=v.end();++it){if(it!=v.begin()){cerr<<", ";}cerr<<*it;}cerr<<"]";return o;}
void deb(){cerr<<"\n";}template<class T,class...Ts>void deb(const T&t,const Ts&...args){cerr<<t;if(sizeof...(args)!=0){cerr<<" ";}deb(args...);}
#else
#define deb(...)
#endif
signed main() {
int N, M;
cin >> N >> M;
vector<vector<int>> cons(N);
for (int m=0; m<M; ++m) {
int a,b;
cin>>a>>b;
--a; --b;
cons[a].push_back(b);
cons[b].push_back(a);
}
vector<int> dists(N, numeric_limits<int>::max());
dists[0] = 0;
queue<int> q;
q.push(0);
while(!q.empty()) {
int a = q.front();
deb(a, dists[a]);
q.pop();
for(auto b : cons[a]) {
if (dists[b] == numeric_limits<int>::max()) {
dists[b] = dists[a] + 1;
q.push(b);
}
}
}
deb(dists);
auto ma = *max_element(dists.begin(), dists.end());
if (ma == numeric_limits<int>::max()) {
cout << -1 << endl;
} else {
cout << ((int)ceil(log2(ma)) + 1) << endl;
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3612kb
input:
100 99 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50 51 51 52 52 5...
output:
8
result:
ok correct
Test #2:
score: 0
Accepted
time: 39ms
memory: 9540kb
input:
100000 99999 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50 51 51 5...
output:
18
result:
ok correct
Test #3:
score: 0
Accepted
time: 1ms
memory: 3800kb
input:
100 978 1 4 1 68 1 8 1 73 1 76 1 12 1 77 1 78 1 79 1 15 1 16 1 84 1 85 1 25 1 89 1 26 1 90 1 27 1 28 1 94 1 95 1 31 1 33 1 34 1 100 1 38 1 44 1 52 1 53 1 58 1 61 1 63 2 64 2 4 2 68 2 70 2 6 2 8 2 73 2 12 2 77 2 13 2 79 2 16 2 17 2 84 2 21 2 86 2 89 2 26 2 28 2 94 2 33 2 100 2 38 2 39 2 41 2 44 2 47 ...
output:
-1
result:
ok correct
Test #4:
score: 0
Accepted
time: 41ms
memory: 10048kb
input:
100000 99915 1 59573 1 20983 2 14663 3 24672 3 15413 3 82843 4 51506 4 5545 4 72106 5 66060 6 89257 7 70816 7 56618 8 95085 9 46847 10 31756 11 49190 12 21610 13 636 13 50445 14 73465 14 30984 15 61922 16 5942 17 23556 17 14949 17 53579 17 55758 18 50192 18 89426 18 39461 18 39239 18 15759 19 46987 ...
output:
-1
result:
ok correct
Test #5:
score: 0
Accepted
time: 0ms
memory: 3632kb
input:
100 99 1 17 1 40 2 80 2 86 3 33 4 79 5 56 6 20 6 25 6 29 6 13 7 83 7 40 8 11 8 76 9 31 10 88 11 68 11 74 12 67 13 82 14 81 14 77 15 86 15 72 15 58 16 73 17 51 17 84 17 70 17 41 17 74 18 72 19 33 21 84 22 30 23 67 23 54 24 79 26 93 27 29 28 88 28 73 28 61 29 84 29 86 29 56 29 31 30 70 30 43 32 89 33 ...
output:
5
result:
ok correct
Test #6:
score: 0
Accepted
time: 43ms
memory: 10212kb
input:
100000 99999 1 66561 1 58459 1 96014 2 67702 2 36203 3 46929 4 85854 5 66325 6 97789 7 19120 7 15926 8 84370 8 40333 9 73695 10 44248 11 75321 12 82342 12 54247 12 83864 13 68505 14 22565 14 62853 14 84216 15 77958 16 82480 16 39303 17 58049 18 54892 19 80471 19 90767 20 97984 20 57750 20 48520 21 4...
output:
6
result:
ok correct
Test #7:
score: 0
Accepted
time: 1ms
memory: 3688kb
input:
100 500 1 81 1 51 1 3 1 70 1 8 1 13 1 62 1 94 2 80 2 36 2 54 2 8 2 89 2 58 2 91 2 76 2 77 2 47 3 96 3 81 3 33 3 34 3 85 3 54 4 16 4 66 4 20 4 53 4 23 4 7 4 72 4 89 4 91 4 11 5 17 5 97 5 18 5 68 5 27 5 75 5 28 5 63 6 17 6 34 6 100 6 54 6 87 6 10 6 91 6 93 6 46 6 63 7 64 7 69 7 73 7 74 7 44 7 77 7 14 ...
output:
3
result:
ok correct
Test #8:
score: 0
Accepted
time: 44ms
memory: 8180kb
input:
50000 100000 1 14577 1 41524 1 35064 1 20700 2 25987 3 11923 3 28901 3 30760 3 23064 3 46761 3 43051 4 47043 4 4008 4 25993 4 24265 4 28122 5 24739 5 36622 5 3103 6 44448 6 48336 6 29161 6 49979 7 43568 7 10633 8 12642 8 35021 8 30510 9 30948 9 10517 9 32566 9 39004 9 30190 10 741 10 24040 10 13644 ...
output:
5
result:
ok correct
Test #9:
score: 0
Accepted
time: 0ms
memory: 3788kb
input:
100 1000 1 65 1 67 1 8 1 9 1 10 1 11 1 13 1 15 1 16 1 20 1 21 1 24 1 25 1 26 1 28 1 29 1 31 1 33 1 35 1 36 1 39 1 40 1 41 1 42 1 43 1 44 1 46 1 50 1 51 1 52 1 53 1 54 1 55 1 58 1 61 1 62 1 63 2 22 3 17 3 18 3 4 3 38 3 56 3 57 3 59 4 64 4 32 4 17 4 5 4 38 4 57 4 59 5 32 5 48 5 64 5 38 5 57 5 27 5 59 ...
output:
7
result:
ok correct
Test #10:
score: 0
Accepted
time: 40ms
memory: 10152kb
input:
100000 100000 1 87531 2 83859 2 338 2 18820 2 82487 3 74768 3 69187 3 6841 4 81493 4 32839 5 12223 6 23013 6 41740 7 67640 8 48631 8 35597 9 31712 9 71158 10 20384 11 41494 12 80565 12 8551 12 74168 13 20251 14 23906 14 1653 14 84506 15 60423 16 27023 17 25492 17 28713 18 91308 19 65410 19 88452 20 ...
output:
14
result:
ok correct
Test #11:
score: 0
Accepted
time: 4ms
memory: 4076kb
input:
10000 9999 1 8928 2 4 3 4099 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 24 23 8210 23 2077 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 35 34 8226 34 6183 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 44 43 2088 43 4141 44 45 45 46 ...
output:
15
result:
ok correct
Test #12:
score: 0
Accepted
time: 42ms
memory: 9428kb
input:
100000 99999 1 31874 2 65538 3 24578 3 16389 4 65541 4 65540 5 65538 5 32773 6 65543 6 65542 7 77831 7 4103 8 65542 8 65545 9 65545 9 65544 10 32775 10 98314 11 4106 11 12301 12 98317 12 65551 13 98323 13 98314 14 65549 14 98318 15 18 15 65550 16 39825 16 12810 17 40977 17 98320 18 65555 19 65555 19...
output:
17
result:
ok correct
Test #13:
score: 0
Accepted
time: 0ms
memory: 3536kb
input:
3 2 1 2 1 3
output:
1
result:
ok correct
Test #14:
score: 0
Accepted
time: 0ms
memory: 3828kb
input:
4 5 1 2 1 3 1 4 4 2 4 3
output:
1
result:
ok correct
Test #15:
score: 0
Accepted
time: 24ms
memory: 4936kb
input:
440 96580 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 1 11 1 12 1 13 1 14 1 15 1 16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 1 26 1 27 1 28 1 29 1 30 1 31 1 32 1 33 1 34 1 35 1 36 1 37 1 38 1 39 1 40 1 41 1 42 1 43 1 44 1 45 1 46 1 47 1 48 1 49 1 50 1 51 1 52 1 53 1 54 1 55 1 56 1 57 1 58 1 59 1 60 1 6...
output:
1
result:
ok correct