QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#352491#7995. 图lopzithWA 1ms5252kbC++142.9kb2024-03-13 11:36:592024-03-13 11:36:59

Judging History

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

  • [2024-03-13 11:36:59]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5252kb
  • [2024-03-13 11:36:59]
  • 提交

answer

#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define i64 long long
#define ull unsigned long long
#define Arr std::vector
#define Ptn std::pair
#define fi first
#define se second
#define eb emplace_back
#define pb push_back
#define popc(x) __builtin_popcount(x)
#define FILE(x) freopen(x ".in", "r", stdin), freopen(x ".out", "w", stdout)
#define TEST(x) freopen(x ".in", "r", stdin), freopen("test.out", "w", stdout)
#define debug std::cout << "Running on " << __FUNCTION__ << ' ' << __LINE__ << std::endl;
const int INF = 0x3f3f3f3f;
const int N = 505;
int n, a[N][N], w[N][N], dep[N], fa[N], ans[N][N], op[N][N]; // op  0 -> isTrue
Arr<int> e[N];
Arr< Ptn<int, int> > ret;
inline int read()
{
    int w = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9')
    {
        if (ch == '-') f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9')
    {
        w = (w << 3) + (w << 1) + (ch - 48);
        ch = getchar();
    }
    return w * f;
}

void DFS(int p)
{
    Ptn<int, int> opt = {INF, 0};
    for (auto tt : e[p])
    {
        if (fa[p] == tt) continue;
        if (dep[tt])
        {
            op[tt][p] = op[p][tt] = 1;
            opt = std::min(opt, std::make_pair(dep[tt], tt));
            continue;
        }
        fa[tt] = p;
        dep[tt] = dep[p] + 1;
        DFS(tt);
    }
    if (opt.se)
    {
        int now = p, cnt = 0;
        while (now != opt.se)
        {
            op[now][fa[now]] = 1, op[fa[now]][now] = 1;
            cnt++;
            if (cnt >= n + 5) printf("%d %d %ld %d %d\n", now, p, opt.se, opt.fi), exit(0);
            // printf("%lld %lld\n", now, fa[now]);
            now = fa[now];
        }
    }
}

signed main()
{
    n = read(); for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) w[i][j] = a[i][j] = read();
    for (int k = 1; k <= n; k++)
    {
        for (int i = 1; i <= n; i++)
        {
            for (int j = 1; j <= n; j++)
            {
                a[i][j] = std::min(a[i][j], a[i][k] + a[k][j]);
            }
        }
    }
    for (int s = 1; s <= n; s++)
    {
        for (int i = 1; i <= n; i++) e[i].clear(); memset(op, 0, sizeof(op));
        ret.clear();
        memset(dep, 0, sizeof(dep)); memset(fa, 0, sizeof(fa));
        for (int i = 1; i <= n; i++)
        {
            for (int j = 1; j < i; j++)
            {
                if (a[s][i] + w[i][j] == a[s][j] || a[s][j] + w[i][j] == a[s][i]) e[i].eb(j), e[j].eb(i), ret.pb({i, j});// printf("%lld -> %lld\n", i, j);
            }
        } dep[s] = 1;
        DFS(s); 
        for (auto tt : ret) if (!op[tt.fi][tt.se]) ans[tt.fi][tt.se] = 1, ans[tt.se][tt.fi] = 1;
    }
    for (int i = 1; i <= n; i++) 
    {
        for (int j = 1; j <= n; j++) 
        {
            if (i == j) printf("0");
            else printf("%d", ans[i][j]);
        }
        printf("\n");
    }
    return 0;
}

詳細信息

Test #1:

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

input:

4
0 3 2 100
3 0 8 100
2 8 0 10
100 100 10 0

output:

0110
1000
1001
0010

result:

ok 4 lines

Test #2:

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

input:

4
0 3 2 100
3 0 8 100
2 8 0 10
100 100 10 0

output:

0110
1000
1001
0010

result:

ok 4 lines

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 5252kb

input:

100
0 41659 61282 49636 67326 48035 29694 46438 87384 82143 38685 66540 48746 29800 91786 54931 56232 61941 53423 75707 45135 69244 53802 89998 64199 63778 75825 31745 66975 44537 35793 55663 72647 60768 80884 46657 54066 84568 6266 48213 78216 50369 66761 54861 67607 38509 52250 54210 71135 56840 5...

output:

0 17 89 9 8585

result:

wrong answer 1st lines differ - expected: '000000000000000000000000000000...0000001000000000000000000000010', found: '0 17 89 9 8585'