QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#472064 | #6414. Classical Maximization Problem | UESTC_DECAYALI# | WA | 67ms | 38344kb | C++17 | 1.9kb | 2024-07-11 14:10:45 | 2024-07-11 14:10:46 |
Judging History
answer
#include<cstdio>
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#define RI register int
#define CI const int&
using namespace std;
typedef pair <int,int> pi;
const int N=400005;
int t,n,nx,ny,x[N],y[N],rst[N],vis[N];
vector <pi> v[N],tr[N],ans; vector <int> low[N],rub;
inline void addedge(CI x,CI y,CI z)
{
v[x].push_back(pi(y,z)); v[y].push_back(pi(x,z));
}
inline void DFS1(CI now,CI fa=0)
{
vis[now]=1; for (auto [to,id]:v[now])
if (to!=fa)
{
if (!vis[to]) tr[now].push_back(pi(to,id)),DFS1(to,now);
else low[to].push_back(id);
}
}
inline bool DFS2(CI now,CI lst=0)
{
vector <int> son;
for (auto [to,id]:tr[now])
if (DFS2(to,id)) son.push_back(id);
for (auto x:low[now]) son.push_back(x);
reverse(son.begin(),son.end());
if (son.size()%2)
{
for (RI i=0;i+1<son.size();i+=2)
ans.push_back(pi(son[i],son[i+1]));
if (lst)
{
ans.push_back(pi(lst,son.back()));
return 0;
} else
{
rub.push_back(son.back());
return 1;
}
} else
{
for (RI i=0;i+1<son.size();i+=2)
ans.push_back(pi(son[i],son[i+1]));
return 1;
}
}
int main()
{
//freopen("H.in","r",stdin);
for (scanf("%d",&t);t;--t)
{
RI i; for (scanf("%d",&n),i=1;i<=2*n;++i) scanf("%d%d",&x[i],&y[i]);
for (i=1;i<=2*n;++i) rst[i]=x[i];
sort(rst+1,rst+2*n+1); nx=unique(rst+1,rst+2*n+1)-rst-1;
for (i=1;i<=2*n;++i) x[i]=lower_bound(rst+1,rst+nx+1,x[i])-rst;
for (i=1;i<=2*n;++i) rst[i]=y[i];
sort(rst+1,rst+2*n+1); ny=unique(rst+1,rst+2*n+1)-rst-1;
for (i=1;i<=2*n;++i) y[i]=lower_bound(rst+1,rst+ny+1,y[i])-rst;
for (i=1;i<=nx+ny;++i) v[i].clear(),tr[i].clear(),low[i].clear(),vis[i]=0;
for (i=1;i<=2*n;++i) addedge(x[i],nx+y[i],i);
ans.clear(); rub.clear();
for (i=1;i<=nx+ny;++i) if (!vis[i]) DFS1(i),DFS2(i);
printf("%d\n",ans.size());
for (auto [x,y]:ans) printf("%d %d\n",x,y);
for (i=0;i+1<rub.size();i+=2) printf("%d %d\n",rub[i],rub[i+1]);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 38344kb
input:
3 2 0 0 0 1 1 0 1 1 2 0 0 0 1 0 2 0 3 2 0 0 1 1 2 2 3 3
output:
2 4 2 1 3 2 4 3 2 1 0 1 2 3 4
result:
ok ok (3 test cases)
Test #2:
score: 0
Accepted
time: 66ms
memory: 38060kb
input:
10000 2 -107276936 -310501829 419434212 585811870 -65754386 -491212232 381152038 897148193 3 -474045168 493506332 299114415 540203303 165808153 983551 -506936261 -694189769 766718170 -725540031 975267148 -593051087 1 -818952276 -762387923 584023914 -612401389 6 -77701228 -266484128 659434465 6322062...
output:
0 1 3 4 2 0 4 1 3 2 5 6 0 1 2 0 9 7 11 1 4 6 8 12 2 10 5 3 0 1 3 5 6 12 13 7 8 11 4 2 10 14 9 0 2 1 0 54 1 45 16 35 46 26 33 65 44 5 29 22 20 39 10 9 61 32 21 47 31 43 50 37 12 6 2 62 13 3 11 19 58 51 27 18 24 17 52 23 34 28 49 14 41 25 48 40 63 38 42 59 55 30 60 57 8 56 4 15 66 64 7 53 36 0 4 2 1 3...
result:
ok ok (10000 test cases)
Test #3:
score: 0
Accepted
time: 62ms
memory: 37904kb
input:
10000 1 999855386 999580905 999342928 999615227 21 999601032 999015398 999155628 999176944 999309856 999524434 999121011 999509537 999323572 999685730 999272272 999769606 999450559 999390758 999632027 999178534 999024993 999463838 999784856 999374197 999980525 999366771 999241260 999516879 999599548...
output:
0 2 1 0 30 26 9 19 27 4 41 2 40 12 33 6 3 5 35 7 16 23 42 13 1 17 8 36 28 14 38 29 32 18 20 25 10 15 21 39 37 34 24 31 22 11 0 9 22 3 16 28 30 27 5 2 24 11 6 18 26 4 8 12 7 23 14 13 19 10 29 17 15 1 20 25 21 0 25 21 15 19 17 2 28 11 24 4 20 10 3 27 26 23 5 22 1 13 8 7 6 16 12 14 18 9 0 13 8 20 24 3 ...
result:
ok ok (10000 test cases)
Test #4:
score: 0
Accepted
time: 62ms
memory: 37628kb
input:
10000 5 999984799 999981445 999958394 999984217 999994978 999981258 999955539 999938710 999936554 999963561 999907222 999907508 999938166 999941959 999910567 999986887 999901446 999961092 999994730 999963038 5 999916115 999962400 999948250 999940355 999954204 999920844 999928148 999990369 999978118 ...
output:
0 9 6 8 5 7 4 2 1 10 3 0 10 1 8 4 2 3 9 5 6 7 0 2 5 10 4 17 3 16 11 18 8 12 22 7 13 1 9 21 19 14 6 20 15 0 5 3 2 4 6 7 8 1 0 26 20 27 14 21 4 23 11 22 9 24 3 12 31 32 10 6 30 29 18 7 15 2 19 16 25 28 1 17 13 8 5 0 7 8 2 6 3 4 9 1 10 5 0 2 11 14 1 3 15 9 13 12 5 8 10 6 7 16 4 0 47 21 67 65 66 36 60 2...
result:
ok ok (10000 test cases)
Test #5:
score: 0
Accepted
time: 66ms
memory: 37188kb
input:
10000 1 999990146 999993828 999995909 999996353 56 999999851 999991179 999997250 999997987 999990590 999997316 999997350 999996856 999997034 999996236 999999396 999996897 999991180 999993309 999991265 999995185 999993952 999994054 999990210 999994471 999993201 999995893 999997170 999998971 999998201...
output:
0 1 2 1 111 76 87 61 10 52 54 33 109 3 108 41 22 25 48 7 21 85 8 14 90 92 40 60 53 29 93 102 63 103 81 34 66 82 55 50 100 24 83 78 31 11 43 42 88 51 30 9 79 15 28 70 59 56 27 23 107 68 18 77 58 84 17 57 91 64 49 69 112 96 86 36 94 72 35 38 105 37 65 5 80 75 12 2 4 106 104 62 20 95 47 101 26 13 45 32...
result:
ok ok (10000 test cases)
Test #6:
score: 0
Accepted
time: 67ms
memory: 37612kb
input:
10000 5 999999432 999999813 999999271 999999233 999999043 999999606 999999523 999999406 999999564 999999274 999999641 999999102 999999903 999999858 999999058 999999098 999999974 999999119 999999643 999999620 5 999999370 999999738 999999181 999999907 999999163 999999783 999999393 999999086 999999661 ...
output:
0 3 8 2 1 4 5 6 10 7 9 0 10 6 3 2 9 1 4 5 7 8 0 1 3 4 2 5 6 0 9 3 6 8 4 1 5 10 2 7 1 10 9 34 32 26 20 25 14 13 2 27 8 17 5 15 4 3 11 12 19 31 30 24 18 22 28 33 29 23 7 21 1 6 16 1 13 12 8 4 2 9 14 1 7 5 15 11 10 16 6 3 0 2 3 4 1 0 1 3 2 4 1 44 10 20 34 6 47 33 36 16 48 29 28 32 30 12 38 41 8 13 11 2...
result:
ok ok (10000 test cases)
Test #7:
score: -100
Wrong Answer
time: 67ms
memory: 37348kb
input:
10000 14 -369804569 -904204119 526374829 -824374353 -127549933 -904204119 -68608787 929413707 -68608787 -363454459 526374829 929413707 693313139 -824374353 -127549933 -726843762 526374829 -904204119 526374829 -363454459 526374829 -409731440 693313139 -726843762 693313139 929413707 -68608787 -8243743...
output:
22 19 28 5 10 25 26 16 11 23 14 18 13 6 4 20 17 15 24 9 11 2 10 21 22 7 14 27 24 13 28 8 12 22 17 18 26 3 19 27 9 1 23 21 20 31 21 12 9 34 25 36 13 24 29 27 40 30 35 33 26 15 22 39 38 32 4 7 23 17 5 29 20 16 40 36 32 15 24 12 28 6 31 10 19 33 3 8 1 18 37 16 38 35 13 10 19 17 39 25 2 14 18 31 20 34 3...
result:
wrong answer Integer parameter [name=k] equals to 22, violates the range [0, 14] (test case 1)