QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#196680 | #6526. Canvas | ucup-team870 | WA | 20ms | 67160kb | C++14 | 3.5kb | 2023-10-01 21:24:19 | 2023-10-01 21:24:19 |
Judging History
answer
#include <bits/stdc++.h>
#define rep(i,l,r) for(int i=l; i<=r; i++)
#define IOS {cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);}
using namespace std;
typedef long long ll;
typedef pair<ll,int> P;
const int N = 1000010;
vector <int> ef[N];
vector <P> eb[N];
int ans[N], tag[N], ss, tt, inq[N], sum, rere[N], yes[N], inst[N], num, bel[N];
ll low[N];
ll tim, dfn[N];
set<P> ksj;
void erase(int s) {
queue <int> q;
q.push(s);
inq[s] = 1;
ksj.erase(P(dfn[s], s));
sum += 1;
// cout <<s<<"#\n";
while (!q.empty()) {
int u = q.front();
q.pop();
ksj.erase(P(dfn[u], u));
for (auto t: eb[u]) {
int v = t.first;
ans[t.second] = tt--;
if (!inq[v]) q.push(v), inq[v] = 1,sum += 2;
}
}
}
stack<int> st;
void dfs(int u) {
// cout <<u<<endl;
dfn[u] = low[u] = ++tim;
st.push(u), inst[u] = 1;
for (auto v: ef[u]) {
if (!dfn[v]) dfs(v), low[u] = min(low[u], low[v]);
else if (inst[v]) low[u] = min(low[u], low[v]);
}
if (low[u] == dfn[u]) {
int now;
num++;
do {
now = st.top();
st.pop();
bel[now] = num;
inst[now] = 0;
} while (now != u);
}
}
int main() {
int T; scanf("%d", &T);
while (T--) {
int n, m; scanf("%d%d", &n, &m);
ss = 1, tt = m;
rep (i, 1, m) {
int l, r, x, y;
scanf("%d%d%d%d", &l, &x, &r, &y);
yes[l] = yes[r] = 1;
if (x == 1 && y == 1) {
ans[i] = ss++;
}
else if (x == 2 && y == 2) {
ans[i] = tt--;
tag[l] = tag[r] = 2;
}
else {
if (x < y) swap(l, r), swap(x, y);
ef[l].push_back(r);
eb[r].push_back(P(l, i));
}
}
// rep (i, 1, n) if (tag[i] == 2) sum += 2;
rep (i, 1, n) {
if (yes[i] && !dfn[i]) dfs(i), tim -= 2*n ;
}
// cout <<"dfn:\n";
// rep (i, 1, n) cout << i<<':'<<dfn[i]<<" "<<low[i]<<endl;
rep (i, 1, n) dfn[i] = -low[i];
rep (i, 1, n) {
if (yes[i]) ksj.insert(P(dfn[i], i));//, cout << i << ' '<< dfn[i]<<"$$$\n";
}
rep (i, 1, n) {
if (tag[i] == 2 && !inq[i]) {
erase(i);
sum += 1;
}
}
while (ksj.size()) {
int u = (*ksj.begin()).second;
// cout <<u<<"$"<<endl;
// ksj.erase(ksj.begin());
erase(u);
}
cout << sum <<'\n';
rep (i, 1, m) rere[ans[i]] = i;
rep (i, 1, m) {
cout << rere[i] <<' ';
}
cout <<'\n';
rep (i, 1, n) inq[i] = tag[i] = low[i] = dfn[i] = inst[i] = 0, ef[i].clear(), eb[i].clear(), ef[i].shrink_to_fit(), eb[i].shrink_to_fit(), yes[i] =0;
ksj.clear();
// st.clear();
while (st.size()) st.pop();
rep (i, 1, m) ans[i] = 0;
sum = 0;
tim = 0;
num=0;
}
return 0;
}
/*
2
4 4
1 1 2 2
3 2 4 1
1 2 3 2
2 1 4 1
4 2
3 2 4 1
1 2 3 1
1
10 15
5 2 7 2
1 2 2 1
1 2 4 1
4 2 5 1
2 1 6 2
2 1 4 2
2 2 3 1
1 1 3 2
1 2 8 1
3 1 8 2
8 1 10 2
8 2 10 1
8 2 9 1
8 2 9 1
8 1 9 2
1
8 9
1 2 2 1
1 2 4 1
4 2 5 1
2 1 6 2
2 1 4 2
2 2 3 1
1 1 3 2
1 2 8 1
3 1 8 2
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 64164kb
input:
2 4 4 1 1 2 2 3 2 4 1 1 2 3 2 2 1 4 1 4 2 3 2 4 1 1 2 3 1
output:
7 4 2 1 3 5 2 1
result:
ok Correct. (2 test cases)
Test #2:
score: 0
Accepted
time: 0ms
memory: 64204kb
input:
1 10 13 1 1 2 2 2 1 3 2 1 2 3 1 3 1 4 2 4 1 5 2 5 1 6 2 4 2 6 1 7 1 8 2 8 1 9 2 7 2 9 1 5 2 9 1 8 2 10 2 1 1 10 1
output:
19 13 4 3 2 1 5 7 6 8 11 10 9 12
result:
ok Correct. (1 test case)
Test #3:
score: 0
Accepted
time: 0ms
memory: 66404kb
input:
1 7 5 2 1 6 2 1 2 6 1 1 1 5 1 2 2 7 1 1 1 7 2
output:
8 3 2 1 4 5
result:
ok Correct. (1 test case)
Test #4:
score: 0
Accepted
time: 3ms
memory: 66176kb
input:
1 7 6 2 1 7 2 2 1 4 2 1 2 4 1 2 1 6 1 1 1 6 2 2 2 6 1
output:
9 4 3 2 1 6 5
result:
ok Correct. (1 test case)
Test #5:
score: 0
Accepted
time: 7ms
memory: 64936kb
input:
1 7 5 5 2 7 1 5 1 6 2 3 2 7 1 3 2 6 1 6 1 7 2
output:
7 3 1 5 4 2
result:
ok Correct. (1 test case)
Test #6:
score: 0
Accepted
time: 7ms
memory: 67160kb
input:
1 7 6 1 2 5 1 2 1 7 2 1 2 7 1 2 2 7 1 1 1 5 2 1 2 3 1
output:
8 4 3 2 1 5 6
result:
ok Correct. (1 test case)
Test #7:
score: -100
Wrong Answer
time: 20ms
memory: 64624kb
input:
2000 15 16 2 2 3 1 12 2 15 1 3 2 9 1 6 2 14 1 2 1 15 2 5 2 6 1 7 1 10 1 9 2 15 1 2 2 3 1 4 2 12 1 2 2 9 1 5 2 8 2 3 2 13 1 12 1 13 2 9 2 13 1 5 1 14 2 15 15 5 2 11 1 1 2 8 1 8 1 15 2 6 2 8 2 8 2 9 1 1 1 6 2 6 1 9 2 2 2 5 1 2 1 10 2 7 2 10 1 1 1 15 2 5 2 15 1 7 1 11 2 1 1 2 1 5 2 9 1 15 14 3 1 5 2 1 ...
output:
23 7 9 1 15 13 11 3 14 10 8 2 5 6 4 16 12 20 14 1 13 10 9 12 11 6 8 3 2 15 5 7 4 21 2 6 11 10 13 3 14 9 8 12 4 7 1 5 18 7 11 1 5 9 3 4 8 13 12 6 10 14 2 21 6 10 7 2 11 13 3 14 18 12 1 19 16 9 5 17 8 4 15 21 3 2 6 9 13 14 11 8 5 7 4 12 10 1 21 3 8 1 5 14 2 11 15 9 7 6 13 4 12 10 19 11 14 3 2 9...
result:
wrong answer Jury has better answer. Participant 20, jury 21 (test case 42)