QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#734747 | #4892. 序列 | NineSuns | 0 | 89ms | 52860kb | C++14 | 2.5kb | 2024-11-11 14:48:57 | 2024-11-11 14:48:58 |
Judging History
answer
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
const int N = 2e5+5;
int n, m, a[N], b[N], c[N], d[N], p[4], dfn[N*4], low[N*4], sid[N*4], sc, dt, stk[N*4], ed, istk[N*4], mk[N*4];
vector <int> v[N], e[N*4];
map <int, int> id[N];
void tarjan (int p) {
dfn[p] = low[p] = ++dt;
istk[p] = 1; stk[++ed] = p;
for (int i : e[p]) {
if (!dfn[i]) {
tarjan(i); low[p] = min(low[p], low[i]);
}
else if (istk[i]) low[p] = min(low[p], dfn[i]);
}
if (dfn[p] == low[p]) {
int x; ++sc;
do {
x = stk[ed--]; istk[x] = 0;
sid[x] = sc;
} while (x^p);
}
}
int main () {
cin >> n >> m;
for (int i = 1;i <= m;i++) {
int x, y, z, k;
cin >> x >> y >> z >> k;
a[i] = x; b[i] = y; c[i] = z; d[i] = k;
v[x].pb(k); v[y].pb(k); v[z].pb(k);
}
int S = 0;
for (int i = 1;i <= n;i++) v[i].pb(0), v[i].pb(1e9+1);
for (int i = 1;i <= n;i++) {
sort(v[i].begin(), v[i].end());
v[i].resize(unique(v[i].begin(), v[i].end())-v[i].begin());
for (int j : v[i]) id[i][j] = ++S; //, cout << i << " " << j << " " << S << endl;
}
// cout << endl;
for (int i = 1;i <= n;i++) {
for (int j : v[i]) {
if (j <= 1e9) e[id[i][j]].pb(id[i][j]+1);
}
for (int j : v[i]) {
if (j > 0) e[id[i][j]+S].pb(id[i][j]+S-1);
}
}
for (int i = 1;i <= m;i++) {
p[0] = a[i]; p[1] = b[i]; p[2] = c[i];
sort(p, p+3);
do {
// cout << p[0] << " -> " << p[1] << " " << d[i] << endl;
e[id[p[0]][d[i]]-1].pb(id[p[1]][d[i]]+S);
// e[id[p[0]][d[i]]-1].pb(id[p[2]][d[i]]+S);
e[id[p[0]][d[i]]+1+S].pb(id[p[1]][d[i]]);
// e[id[p[0]][d[i]]+1+S].pb(id[p[2]][d[i]]);
// cout << id[p[0]][d[i]]-1 << " " << id[p[1]][d[i]]+S << endl;
// cout << id[p[0]][d[i]]+1+S << " " << id[p[1]][d[i]] << endl;
} while (next_permutation(p, p+3));
}
for (int i = 1;i <= S+S;i++) if (!dfn[i]) tarjan(i);
for (int i = 1;i <= n;i++) {
for (int j : v[i]) {
if (j <= 1e9) {
if (sid[id[i][j]] == sid[id[i][j]+1+S]) {
cout << "NO"; return 0;
}
}
}
}
// for (int i = 1;i <= S*2;i++) cout << sid[i] << " "; cout << endl;
cout << "YES\n";
for (int i = 1;i <= n;i++) {
int k = 1e9;
for (int j : v[i]) {
if (sid[id[i][j]+S] >= sid[id[i][j]]) {
k = j; break;
}
// cout << sid[id[i][j]] << " " << sid[id[i][j]+S] << " " << j << endl;
// if (max(sid[id[i][j]], sid[id[i][j]+S]) <= max(sid[id[i][k]], sid[id[i][k]+S])) k = j;
}
// cout << endl;
cout << max(1, min(k, (int)1e9)) << " ";
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 4ms
memory: 45276kb
input:
10 10 6 3 10 133562624 8 7 6 685486592 4 2 7 332482851 10 8 9 211550017 2 10 1 165556251 10 8 5 211550017 6 8 2 332482851 4 9 2 332482851 8 1 4 193658790 9 6 10 728674154
output:
YES 165556251 332482851 1 332482851 1000000000 728674154 685486592 211550017 1000000000 165556251
result:
wrong answer the 1-th condition is not satisfied
Subtask #2:
score: 0
Wrong Answer
Test #9:
score: 10
Accepted
time: 8ms
memory: 46576kb
input:
40 9880 4 19 31 610502845 10 19 33 190412843 21 24 39 649028784 16 22 40 569593239 5 9 37 550862419 11 23 40 654613112 6 18 23 492267246 22 23 30 538715841 6 16 24 407919735 5 16 18 388907784 2 16 18 388907784 21 24 28 281403057 7 12 27 451830401 3 11 16 508407438 15 33 36 561955959 6 23 29 70605893...
output:
YES 877488996 197498120 508407438 610502845 209356929 706058934 655952999 624132238 550862419 32695410 654613112 72694954 399757770 396827347 561955959 407919735 779328631 388907784 190412843 657895429 832003778 569593239 492267246 32695410 718125822 812463588 451830401 281403057 1000000000 53871584...
result:
ok solution is correct
Test #10:
score: 0
Wrong Answer
time: 89ms
memory: 52860kb
input:
80 82160 8 15 41 111467584 35 54 58 471689837 51 66 69 545620573 20 63 76 46182451 15 34 40 54922534 19 27 49 410013534 6 13 18 849916477 3 12 30 436881726 8 23 54 239683045 6 37 40 544597112 29 52 70 792746131 7 52 75 478735558 11 50 74 735803963 4 28 50 415323204 23 54 68 347125331 33 67 70 525526...
output:
YES 325002529 459824851 295082589 415323204 815182959 1000000000 478735558 111467584 372443066 865933468 870762944 436881726 849916477 838601559 30644239 1000000000 236051181 278519554 906172939 46182451 284349661 777302867 514711056 91113251 393446574 393984539 410013534 478037910 848158501 8399852...
result:
wrong answer the 1381-th condition is not satisfied
Subtask #3:
score: 0
Skipped
Dependency #1:
0%
Subtask #4:
score: 0
Skipped
Dependency #2:
0%