QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#235371 | #6503. DFS Order 3 | stcmuyi# | TL | 1170ms | 11336kb | C++20 | 1.6kb | 2023-11-02 18:14:20 | 2023-11-02 18:14:20 |
Judging History
answer
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define i64 long long
#define int long long
#define endl '\n'
#define lb(x) ((x) & (-x))
using namespace std;
const i64 mod = 1e9+7;
const int maxn = 1e4+10;
signed main()
{
IOS;
int t; cin >> t;
while(t--)
{
int n; cin >> n;
vector<int> a(n+1);
vector<vector<int>> cnt(n+1,vector<int>(n+1));
for(int i = 1; i <= n; ++i)
{
for(int j = 1; j <= n; ++j) cin >> a[j];
for(int j = 2; j <= n; ++j)
{
for(int k = 1; k < j; ++k)
{
int x = a[j],y = a[k];
if(x > y) swap(x,y);
cnt[x][y] += n-j+2;
}
}
}
struct node{int x,y,z; };
vector<node> v;
for(int i = 1; i <= n; ++i)
{
for(int j = i+1; j <= n; ++j) v.push_back({i,j,cnt[i][j]});
}
sort(v.begin(),v.end(),[&](node a,node b) { return a.z > b.z; });
vector<int> f(n+1);
for(int i = 1; i <= n; ++i) f[i] = i;
auto get = [&](auto self,int x) -> int
{
if(f[x] == x) return x;
return f[x] = self(self,f[x]);
};
vector<pair<int,int>> ans;
for(node &a : v)
{
int x = get(get,a.x),y = get(get,a.y);
if(x != y)
{
ans.push_back({a.x,a.y});
f[x] = y;
}
}
for(auto &[x,y] : ans) cout << x << ' ' << y << endl;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3580kb
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 2 3 1 2 2 3 2 4 1 2 2 4 1 3 3 5
result:
ok correct answer! (4 test cases)
Test #2:
score: 0
Accepted
time: 144ms
memory: 3892kb
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:
4 5 1 2 1 4 4 6 6 7 1 3 3 8 1 10 9 10 2 8 3 8 1 4 3 4 8 9 6 9 4 5 5 7 7 10 1 9 3 10 8 10 5 9 9 10 5 6 2 8 2 4 5 7 5 7 1 6 6 7 7 8 3 8 6 10 2 10 6 9 2 4 4 7 1 5 5 7 1 9 3 7 8 9 3 6 3 10 2 10 3 8 1 10 4 8 5 10 8 10 6 10 8 9 7 9 2 6 6 7 5 7 3 7 5 8 2 3 4 8 2 10 2 9 1 10 2 4 2 3 4 7 6 7 1 4 1 9 4 8 9 10...
result:
ok correct answer! (20000 test cases)
Test #3:
score: 0
Accepted
time: 330ms
memory: 4028kb
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:
47 79 79 82 46 82 29 82 29 77 70 77 12 81 1 29 16 81 1 51 6 16 1 45 6 23 20 45 23 37 15 20 37 74 15 66 12 47 52 74 20 21 38 85 42 52 17 47 21 71 17 50 38 69 13 74 38 50 35 69 45 83 13 65 14 69 12 91 57 91 14 60 40 91 44 60 11 44 36 44 60 86 28 86 38 58 40 68 58 89 61 89 34 58 7 34 34 92 39 92 39 59 ...
result:
ok correct answer! (200 test cases)
Test #4:
score: 0
Accepted
time: 1170ms
memory: 11336kb
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...
output:
200 226 226 270 123 270 226 417 116 466 163 417 186 466 200 466 11 186 11 73 73 170 11 203 11 46 46 252 11 312 11 117 117 287 117 263 263 410 90 410 24 90 90 198 177 263 68 174 20 176 177 413 111 174 329 466 176 196 111 455 266 329 40 233 97 176 37 455 266 271 199 233 260 276 97 273 40 338 93 455 27...
result:
ok correct answer! (8 test cases)
Test #5:
score: -100
Time Limit Exceeded
input:
2 1000 1 586 727 909 178 211 319 562 12 759 714 885 988 612 507 670 288 932 608 333 649 663 14 826 874 930 968 965 780 353 558 76 787 617 815 181 31 552 3 761 398 814 740 841 789 282 636 894 179 569 566 408 225 334 671 294 101 634 218 270 412 463 400 495 804 710 262 93 572 18 673 808 862 711 350 603...