QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#5025#460. Colored GraphLenstar0 661ms61064kbC++112.3kb2020-10-20 14:41:062021-12-19 05:44:06

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2021-12-19 05:44:06]
  • 评测
  • 测评结果:0
  • 用时:661ms
  • 内存:61064kb
  • [2020-10-20 14:41:06]
  • 提交

answer

#include <bits/stdc++.h>

const int N = 5e5 + 10;
using pii = std::pair<int, int>;
using sit = std::set<int>::iterator;
#define mkp(a, b) std::make_pair(a, b)

inline int read()
{
    int x = 0;
    char ch = getchar();
    while (!isdigit(ch)) ch = getchar();
    while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
    return x;
}

std::map<pii, int> Map;
long long X, Y, Z, P[N];
pii ans[N];
int cnt = 0;
std::set<int> A, B;

inline int calc(int u, int v)
{
    return (X * std::min(u, v) + Y * std::max(u, v)) % Z >= P[u] + P[v];
}

inline int Ask(int u, int v)
{
    if (u > v) std::swap(u, v);
    return Map.count(mkp(u, v)) ? Map[mkp(u, v)] : calc(u, v);
}

inline int pre(int u)
{
    sit it = A.lower_bound(u); 
    if (it == A.begin()) it = A.end();
    return *--it;
}

inline int suf(int u)
{
    sit it = A.upper_bound(u);
    if (it == A.end()) it = A.begin();
    return *it;
}

inline void upd(int u)
{
    int p = pre(u), s = suf(u);
    if (Ask(u, p) != Ask(u, s)) B.insert(u);
    else if (B.find(u) != B.end()) B.erase(u);
}

inline int solve()
{
    if (B.empty())
    {
        sit it1 = A.begin(), it2 = it1; 
        int col = Ask(*it1, *++it2);
        for (; it2 != A.end(); it1 = it2++)
            ans[++cnt] = mkp(*it1, *it2);
        return col;
    }
    int u = *B.begin(), p = pre(u), s = suf(u);
    int col1 = Ask(u, p), col2 = Ask(u, s);
    A.erase(u), B.erase(B.begin()), upd(p), upd(s);
    int col = solve();
    ans[++cnt] = mkp(u, col1 == col ? p : s);
    return col;
}

int main()
{
    int n = read(), m = read();
    for (int i = 1; i <= m; ++i)
    {
        int u = read(), v = read();
        if (u > v) std::swap(u, v);
        Map[mkp(u, v)] = read();
    }
    X = read(), Y = read(), Z = read();
    for (int i = 1; i <= n; ++i) P[i] = read();
    // for (int i = 1; i <= n; ++i) suf[i] = i + 1, pre[i] = i - 1;
    // pre[1] = n, suf[n] = 1;
    // for (int i = 1; i <= n; ++i)
    //     for (int j = i + 1; j <= n; ++j)
    //         printf("%d %d %d\n", i, j, Ask(i, j));
    for (int i = 1; i <= n; ++i) A.insert(i);
    for (int i = 1; i <= n; ++i) upd(i);
    solve();
    for (int i = 1; i <= cnt; ++i) printf("%d %d\n", ans[i].first, ans[i].second);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 661ms
memory: 61064kb

input:

439947
70564
261418 81226 0
391157 185738 1
291864 124280 1
224287 253065 0
254187 331805 1
93992 112583 0
3774 31281 1
413605 291199 1
123118 278877 0
383287 374927 0
219696 430048 1
374944 272292 0
156453 15904 0
13652 163529 1
291676 57172 1
268448 195409 0
242654 300684 1
174795 208807 1
216759 123623 1
254209 264578 1
407424 172906 0
21164 297845 1
111755 149875 1
203860 424465 1
275710 160996 0
365668 371841 0
429822 241152 0
275198 109336 1
66424 251337 0
113416 5400 0
297211 370277 1
169...

output:

8 12
12 13
13 14
14 15
15 16
16 17
17 20
20 21
21 22
22 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 58
58 59
59 65
65 66
66 67
67 68
68 69
69 78
78 79
79 80
80 81
81 82
82 83
83 84
84 85
85 86
86 87
87 91
91 92
92 93
93 94
94 95
95 96
96 97
97 98
98 99
99 100
100 105
105 106
106 115
115 116
116 117
117 127
127 128
128 129
129 130
130 131
131 132
132 133
133 134
134 135
135 147
147 148
148 149
149 151
151 152
152 154
154 155
155 160
160 161
161 162
162 163
163 164
164 165
16...

result:

FAIL Your edges have different colors on #34(83, 84)