QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#111321 | #4996. Icy Itinerary | PetroTarnavskyi# | RE | 7ms | 10944kb | C++17 | 2.3kb | 2023-06-06 18:38:51 | 2023-06-06 18:38:55 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define FOR(i, a, b) for (int i = (a); i<(b); ++i)
#define RFOR(i, b, a) for (int i = (b)-1; i>=(a); --i)
#define MP make_pair
#define PB push_back
#define F first
#define S second
typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
const int N = 100'447;
VI g[N];
VI g2[N];
int s[N];
bool used[N];
set<int> all;
set<PII> cmp;
int lef;
int dfs1(int v)
{
used[v] = 1;
s[v] = 1;
for (auto to : g[v])
{
if (!used[to])
{
s[v] += dfs1(to);
g2[v].PB(to);
}
}
return s[v];
}
int dfs2(int v)
{
all.erase(v);
auto it = all.begin();
s[v] = 1;
FOR (i, 0, SZ(g[v]))
{
if (it == all.end()) return s[v];
auto to = g[v][i];
if (to < *it) continue;
if (to == *it)
{
it++;
continue;
}
to = *it;
s[v] += dfs2(to);
g2[v].PB(to);
it = all.lower_bound(to);
}
while(it != all.end()){
int to = *it;
//cerr << v << ": " << to << endl;
s[v] += dfs2(to);
g2[v].PB(to);
it = all.lower_bound(to);
}
return s[v];
}
void restore(int v)
{
cout << v + 1 << ' ';
cmp.erase({s[v], v});
int tot = -1;
if(!cmp.empty())
tot = cmp.rbegin()->second;
for (auto to : g2[v])
{
cmp.insert({s[to], to});
}
if(tot != -1)
restore(tot);
}
void dfs3(int v)
{
cout << v + 1 << ' ';
lef--;
cmp.erase({s[v], v});
int mxOld = (cmp.empty() ? -1 : cmp.rbegin()->second);
for (auto to : g2[v])
{
cmp.insert({s[to], to});
}
if(mxOld != -1 && (cmp.rbegin()->first * 2 < lef + 1 || s[mxOld] == cmp.rbegin()->first)){
restore(mxOld);
cout << endl;
exit(0);
}
sort(ALL(g2[v]), [&](int a, int b)
{
return s[a] > s[b];
});
if(!g2[v].empty())
dfs3(g2[v][0]);
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
lef = n;
FOR (i, 0, m)
{
int a, b;
cin >> a >> b;
a--, b--;
g[a].PB(b);
g[b].PB(a);
}
int sz = dfs1(0);
if (sz != n)
{
FOR (i, 0, n)
{
s[i] = 0;
g2[i].clear();
sort(ALL(g[i]));
used[i] = false;
all.insert(i);
}
dfs2(0);
/*FOR(i, 0, n){
for(int to : g2[i])
cout << to << " ";
cout << endl;
}*/
}
dfs3(0);
cout << endl;
assert(lef == 0);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 8104kb
input:
4 4 1 2 1 3 1 4 3 4
output:
1 3 2 4
result:
ok qwq
Test #2:
score: 0
Accepted
time: 0ms
memory: 8100kb
input:
5 0
output:
1 2 3 4 5
result:
ok qwq
Test #3:
score: 0
Accepted
time: 4ms
memory: 8292kb
input:
10 10 7 8 7 5 5 2 6 1 10 7 4 6 5 8 3 2 10 5 1 10
output:
1 2 4 3 5 6 7 9 8 10
result:
ok qwq
Test #4:
score: 0
Accepted
time: 7ms
memory: 8292kb
input:
2 1 1 2
output:
1 2
result:
ok qwq
Test #5:
score: 0
Accepted
time: 2ms
memory: 8132kb
input:
2 0
output:
1 2
result:
ok qwq
Test #6:
score: 0
Accepted
time: 1ms
memory: 8140kb
input:
3 1 1 3
output:
1 2 3
result:
ok qwq
Test #7:
score: 0
Accepted
time: 4ms
memory: 8236kb
input:
10 40 10 9 4 5 2 7 3 4 4 7 4 9 7 3 5 10 5 9 8 1 1 10 6 7 6 9 9 8 10 7 7 8 8 3 10 3 2 1 1 5 6 1 5 7 2 5 3 9 2 8 1 9 4 1 1 7 4 10 2 10 3 1 4 6 9 7 3 6 2 3 8 4 6 8 3 5 4 2 2 6
output:
1 8 9 10 5 4 3 7 2 6
result:
ok qwq
Test #8:
score: 0
Accepted
time: 4ms
memory: 8144kb
input:
10 45 7 2 6 3 7 10 5 1 1 9 6 8 10 1 2 10 10 8 10 5 6 2 4 3 6 7 10 3 3 2 1 8 10 9 2 5 9 2 4 1 8 3 8 2 5 7 4 8 9 4 1 7 7 3 6 10 4 2 6 4 10 4 3 1 8 5 4 7 1 6 9 5 3 9 6 5 5 4 9 7 2 1 8 9 3 5 6 9 7 8
output:
1 5 10 7 2 6 3 4 8 9
result:
ok qwq
Test #9:
score: 0
Accepted
time: 5ms
memory: 8292kb
input:
15 40 12 11 11 6 5 11 15 14 10 14 15 5 1 11 10 12 4 3 6 4 4 9 2 11 6 12 13 7 7 9 10 9 1 2 9 11 2 6 7 14 2 9 3 13 9 1 2 7 8 11 1 10 13 1 4 15 3 7 2 15 6 5 10 15 4 14 15 6 2 4 3 11 1 14 2 8 1 8 10 7
output:
1 11 12 10 14 15 5 6 4 3 13 7 9 2 8
result:
ok qwq
Test #10:
score: 0
Accepted
time: 2ms
memory: 8048kb
input:
15 1 13 6
output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
result:
ok qwq
Test #11:
score: 0
Accepted
time: 6ms
memory: 8164kb
input:
150 150 110 99 80 122 55 67 24 47 73 68 150 13 94 140 146 59 136 28 94 134 131 2 26 105 65 79 57 37 116 102 84 16 110 78 72 5 34 8 8 43 83 57 49 146 43 112 54 139 95 13 11 95 75 29 29 30 52 14 118 56 4 51 18 146 31 113 56 69 44 14 63 123 44 66 101 122 52 10 16 118 71 93 22 113 28 88 5 108 16 48 84 1...
output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 16 15 17 18 19 20 21 22 23 24 25 26 27 28 29 31 30 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 71 70 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 101 102 ...
result:
ok qwq
Test #12:
score: 0
Accepted
time: 1ms
memory: 8384kb
input:
1500 1500 370 639 1046 375 1191 907 782 923 1369 196 998 194 640 331 309 631 1053 1076 887 1112 650 1437 2 1133 847 302 647 81 22 691 772 14 1112 62 266 1399 865 980 1302 1146 1007 575 1448 261 1489 1189 1134 1009 7 1175 1369 942 709 365 675 514 1021 1250 1415 2 976 746 564 388 431 326 43 147 385 81...
output:
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 101 102 ...
result:
ok qwq
Test #13:
score: 0
Accepted
time: 0ms
memory: 10944kb
input:
15000 15000 11602 9990 5492 14226 2633 14599 7956 12544 1258 1198 13788 3283 171 3770 8226 10782 915 6735 7186 14219 12806 1549 8783 5596 3692 9668 370 4654 13811 4032 835 12990 14273 14020 8902 7798 7405 4524 7476 1864 7786 14984 4367 13552 2927 2463 1929 3198 97 5800 14012 5674 6283 827 13860 1139...
output:
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 101 102 ...
result:
ok qwq
Test #14:
score: -100
Runtime Error
input:
300000 0