QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#249990#3411. Absurdistan RoadsErtugrul28WA 120ms23140kbC++233.2kb2023-11-12 19:14:552023-11-12 19:14:56

Judging History

你现在查看的是最新测评结果

  • [2023-11-12 19:14:56]
  • 评测
  • 测评结果:WA
  • 用时:120ms
  • 内存:23140kb
  • [2023-11-12 19:14:55]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;

//#define int long long int
#define PB   push_back
using pii = pair<int, int>;
using vi  = vector<int>;
using vvi = vector<vi>;
#define Endl "\n"
#define sixeof sizeof
#define NOT ~
static int tc = 0;
const int mxn = 1e6+2;
const int lgn = 20;
const int mod = (119<<23)+1;
// const int mod = 1e9+7;

int bigMod(int b, int p, const int mod) {
    int res = 1;
    b%=mod;
    while(p) {
        if(p&1) res = (res * b)%mod;
        b = (b * b)%mod;
        p/=2;
    }
    return res;
}
// a
// z
int mul(long long x, long long y) {
    x*=y;
    return (int)(x%mod);
}
int add(long long x, long long y) {
    x+=y;
    if(x>=mod) x-=mod;
    if(x<mod) x+=mod;
    return (int)x;
}
struct DSU {
    int n;
    vector<int>p, rnk;
    DSU(int n) {
        p = vector<int>(n+1, 0);
        rnk = vector<int>(n+1, 1);
        iota(begin(p), end(p), 0);
    }
    int find(int u) {
        return p[u]==u?u:find(p[u]);
    }
    int merge(int u, int v) {
        u = find(u);
        v = find(v);
        if(u^v) {
            if(rnk[u]<rnk[v]) swap(u, v);
            p[v] = u;
            rnk[u]+=rnk[v];
            return rnk[u];
        }
        return 0;
    }
};
const int N = 2e3+2;
int n;
int b[N][N], c[N][N];
int getH(int x, int y) {
    return (x-1)*n+y-1;
}
void get(int temp, int&x,  int&y) {
    if(temp<0 || n==0) assert(0);
    x = temp/n+1;
    y = temp%n+1;
}
vector<int> g[N];
int root;
void dfs(int u, int p) {
    for(int &v: g[u]) {
        if(v^p) {
            c[root][v] = c[root][u]+1;
            dfs(v, u);
        }
    }
}
void solve() {
    if(!(cin >> n)) exit(0);
    vector<int> v;
    if(tc) cout << Endl;
    tc++;
    for(int i=1; i<=n; i++) {
        for(int j=1; j<=n; j++) {
            cin >> b[i][j];
            if(i<j)
                v.push_back(getH(i, j));
        }
    }
    sort(begin(v), end(v), [&](int t2,  int t3) {
        int x, y, xp, yp;
        get(t2, x, y);
        get(t3, xp, yp);
        return (b[x][y]<b[xp][yp]);
    });
    vector<int> edges;
    DSU dsu(n);
    int nttken = 0;
    for(int i=0; i<v.size(); i++) {
        int x, y;
        get(v[i], x, y);
        if(dsu.merge(x, y)) {
            edges.push_back(v[i]);
            v[i] = -1;
            g[x].push_back(y);
            g[y].push_back(x);
        }
        if(v[i]>=0) nttken = v[i];
    }
    for(int i=1; i<=n; i++) {
        root = i;
        c[i][i] = 0;
        dfs(i, i);
    }
    for(int i=0; i<v.size(); i++) {
        if(v[i]==-1) continue;
        int x, y;
        get(v[i], x, y);
        if(b[x][y]==c[x][y]) continue;
        int xp, yp;
        get(nttken,xp,yp);
        if(b[x][y]<b[xp][yp]) nttken = v[i];
    }
    edges.push_back(nttken);
    for(int i=0; i<n; i++) {
        int x, y;
        get(edges[i], x, y);
        cout <<x <<" "<<y<<" "<<b[x][y]<<Endl;
    }
    for(int i=1; i<=n; i++) g[i].clear();

}
int32_t main() {
   ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t, tc=1e8;
    while(tc--)
//    for(cin >> t; tc<=t; tc++)

    {
        // cout <<"Case "<<tc<<":\n";
//             cout << "Case #"<<tc<<": ";
        solve();
    }
}
// a

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5836kb

input:

40
0 49907 81666 63518 54444 18148 77129 45370 9074 86203 77129 36296 58981 13611 86203 58981 4537 90740 40833 27222 36296 4537 45370 22685 68055 72592 68055 63518 72592 81666 22685 31759 54444 40833 18148 9074 31759 13611 27222 49907
49907 0 49907 68055 77129 31759 27222 4537 40833 36296 54444 1361...

output:

10 30 4537
7 26 4537
3 11 4537
7 30 4537
5 16 4537
8 19 4537
14 35 4537
31 35 4537
14 36 4537
17 36 4537
2 8 4537
2 33 4537
26 27 4537
15 18 4537
23 40 4537
4 16 4537
10 18 4537
23 34 4537
9 22 4537
9 38 4537
31 39 4537
27 28 4537
4 25 4537
6 38 4537
12 32 4537
25 29 4537
21 37 4537
5 40 4537
21 34 ...

result:

ok  (2 test cases)

Test #2:

score: 0
Accepted
time: 1ms
memory: 6132kb

input:

52
0 59280 17784 77064 5928 53352 50388 74100 11856 41496 35568 71136 35568 29640 17784 11856 68172 44460 14820 8892 23712 38532 2964 23712 65208 68172 8892 56316 53352 44460 14820 59280 20748 2964 38532 62244 32604 62244 50388 5928 29640 32604 47424 71136 56316 20748 26676 74100 65208 47424 41496 2...

output:

22 51 2964
4 48 2964
7 43 2964
36 49 2964
1 34 2964
28 32 2964
21 47 2964
2 36 2964
12 17 2964
16 20 2964
24 46 2964
5 27 2964
16 19 2964
34 40 2964
21 33 2964
6 39 2964
12 48 2964
32 38 2964
15 46 2964
30 51 2964
2 45 2964
30 43 2964
4 8 2964
13 35 2964
13 37 2964
8 44 2964
29 45 2964
24 52 2964
3 ...

result:

ok  (2 test cases)

Test #3:

score: 0
Accepted
time: 120ms
memory: 23140kb

input:

1000
0 66192 23640 41961 42158 1576 7486 88256 9259 75845 19109 73284 17139 31717 55554 91999 76042 65404 44128 43734 5122 46295 90226 82346 43537 32899 94757 63434 30535 34081 69147 47871 68556 71708 85104 10638 85104 2561 13396 54963 33096 79194 20685 59494 9653 68556 81755 70329 55948 33490 29944...

output:

437 561 197
435 978 197
436 503 197
218 415 197
137 495 197
33 433 197
512 655 197
76 551 197
306 514 197
218 1000 197
76 517 197
802 961 197
937 989 197
511 896 197
513 520 197
219 999 197
123 720 197
220 596 197
220 660 197
510 525 197
509 970 197
703 967 197
509 939 197
437 977 197
221 460 197
34...

result:

ok  (2 test cases)

Test #4:

score: -100
Wrong Answer
time: 1ms
memory: 7824kb

input:

38
0 266 3861 3872 3772 3029 3553 2995 1398 2545 1492 3162 3086 4487 2132 2404 3920 3195 789 1510 2992 2151 1307 2249 1563 3060 2735 2816 1530 3409 2937 2794 1672 2555 1506 2197 2504 3413
266 0 3595 3606 3506 2763 3287 2729 1132 2279 1226 2896 2820 4221 1866 2138 3654 2929 523 1244 2726 1885 1041 19...

output:

20 35 4
11 35 14
6 8 34
4 17 48
12 13 76
9 23 91
25 33 109
7 30 144
21 32 198
16 36 207
23 25 256
6 21 264
1 2 266
32 37 290
36 37 307
16 27 331
10 36 348
34 36 358
8 38 418
19 23 518
2 19 523
26 37 556
15 29 602
28 36 619
29 36 667
27 30 674
13 16 682
11 19 703
5 14 715
31 36 740
19 29 741
11 24 75...

result:

wrong answer TC 1: Wrong distance between cities 1 and 3. Expecting 3861, got 4156. (test case 1)