QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#109186 | #6503. DFS Order 3 | snowy2002 | TL | 1534ms | 4244kb | C++17 | 1.8kb | 2023-05-27 19:07:44 | 2023-05-27 19:07:46 |
Judging History
answer
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#define time chrono::system_clock::now().time_since_epoch().count()
#include<ext/pb_ds/tree_policy.hpp>
#define clean(x) memset(x,0,sizeof(x))
#define fil(x,n) fill(x,x+1+n,0)
#define inf 2000000009
#define maxn 1000005
// #define int long long
using namespace std;
using namespace __gnu_pbds;
mt19937_64 rnd(time);
cc_hash_table<int,int>mp;
int read() {
int x=1,res=0;
char c=getchar();
while(c<'0'||c>'9') {
if(c=='-') x=-1;
c=getchar();
}
while(c>='0'&&c<='9') {
res=res*10+(c-'0');
c=getchar();
}
return res*x;
}
set<pair<int,int>>s[1005];
int f[1005];
int fi(int x) {
if(x!=f[x]) f[x]=fi(f[x]);
return f[x];
}
void solve() {
int n=read();
vector id(n+1,vector(n+1,0ll));
for(int i=1;i<=n;i++) s[i].clear();
for(int i=1;i<=n;i++) {
for(int j=1;j<=n;j++) {
int x=read();
id[i][x]=j;
s[i].insert({j,x});
}
}
vector<pair<int,int>>ans;
for(int i=1;i<=n;i++) f[i]=i;
while(s[1].size()>=2) {
vector<int>res;
for(int i=1;i<=n;i++) {
auto u=*s[i].begin();
auto v=*next(s[i].begin());
if(fi(u.second)!=fi(v.second)) {
ans.push_back({u.second,v.second});
f[fi(u.second)]=fi(v.second);
}
auto z=s[i].rbegin()->second;
res.push_back(z);
}
for(int i:res) {
for(int j=1;j<=n;j++) {
s[j].erase({id[j][i],i});
}
}
}
for(auto [u,v]:ans) {
printf("%d %d\n",u,v);
}
}
signed main()
{
int t=read();
while(t--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3688kb
input:
4 2 1 2 2 1 3 1 2 3 2 1 3 3 2 1 4 1 2 3 4 2 1 3 4 3 2 4 1 4 2 1 3 5 1 2 4 3 5 2 4 1 3 5 3 5 1 2 4 4 2 1 3 5 5 3 1 2 4
output:
1 2 1 2 3 2 1 2 3 2 4 2 1 2 2 4 3 5 3 1
result:
ok correct answer! (4 test cases)
Test #2:
score: 0
Accepted
time: 301ms
memory: 3628kb
input:
20000 10 1 2 4 5 6 7 3 8 10 9 2 1 4 5 6 7 3 8 10 9 3 8 1 2 4 5 6 7 10 9 4 5 6 7 1 2 3 8 10 9 5 4 6 7 1 2 3 8 10 9 6 7 4 5 1 2 3 8 10 9 7 6 4 5 1 2 3 8 10 9 8 3 1 2 4 5 6 7 10 9 9 10 1 2 4 5 6 7 3 8 10 1 2 4 5 6 7 3 8 9 10 1 4 3 8 2 9 6 5 7 10 2 8 9 6 3 4 1 5 7 10 3 8 2 9 6 4 1 5 7 10 4 1 3 8 2 9 6 5...
output:
1 2 3 8 4 5 6 7 9 10 10 1 3 1 1 4 6 4 1 4 2 8 3 8 5 4 6 9 7 5 10 7 9 8 4 3 1 9 2 4 3 10 5 6 7 5 8 2 8 10 5 9 9 10 1 6 2 4 3 8 5 7 9 6 10 2 10 6 8 7 6 7 1 9 2 10 3 6 4 7 5 1 8 9 10 3 5 7 3 7 1 10 2 6 3 8 4 8 5 10 7 9 6 10 9 8 10 8 1 10 2 3 3 7 4 8 5 8 6 7 9 2 10 2 5 7 1 4 2 3 4 2 5 10 6 7 8 4 9 1 10 ...
result:
ok correct answer! (20000 test cases)
Test #3:
score: 0
Accepted
time: 1534ms
memory: 4244kb
input:
200 100 1 51 45 20 15 66 21 71 83 29 77 70 82 46 79 47 17 50 38 85 69 35 14 60 44 11 36 86 28 58 89 61 34 7 92 39 59 94 63 75 12 81 16 6 23 37 74 52 42 13 65 91 57 40 62 93 72 96 68 26 78 84 43 10 9 33 56 87 97 27 22 80 55 24 98 76 3 18 48 90 64 49 67 4 19 53 32 54 73 8 31 88 99 25 100 5 2 41 95 30 ...
output:
1 51 2 5 3 68 4 19 6 23 7 34 8 73 9 33 10 9 11 44 12 81 13 65 14 60 15 66 16 6 17 50 18 48 20 15 21 71 22 80 23 37 24 98 25 99 26 78 27 97 28 86 29 77 30 95 31 73 32 54 33 56 35 69 36 44 37 74 38 85 39 59 40 91 41 5 42 52 43 10 45 20 46 82 47 79 49 67 50 38 53 32 55 80 56 87 57 91 58 89 60 44 61 89 ...
result:
ok correct answer! (200 test cases)
Test #4:
score: -100
Time Limit Exceeded
input:
8 500 1 164 494 392 66 328 402 15 156 395 234 78 241 304 4 54 439 387 83 460 220 490 369 343 172 190 108 122 173 384 290 403 231 254 70 29 294 359 153 59 228 474 167 222 491 357 169 383 50 103 447 84 344 237 376 457 238 17 363 131 34 244 472 104 154 322 140 488 193 390 245 147 31 189 191 221 259 456...