QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#188248#5492. Toll Roadstriplem5ds#WA 410ms78040kbC++232.3kb2023-09-25 17:24:172023-09-25 17:24:17

Judging History

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

  • [2023-09-25 17:24:17]
  • 评测
  • 测评结果:WA
  • 用时:410ms
  • 内存:78040kb
  • [2023-09-25 17:24:17]
  • 提交

answer

/// Msaa el 5ra
#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2,fma")

#include "bits/stdc++.h"

using namespace std;

#define pb push_back
#define F first
#define S second
#define f(i, a, b)  for(int i = a; i < b; i++)
#define all(a)  a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define sz(x) (int)(x).size()
#define mp(x, y) make_pair(x,y)
#define popCnt(x) (__builtin_popcountll(x))
#define int ll

using ll = long long;
using ii = pair<int, int>;
using ull = unsigned long long;

const int N = 2e5 + 5, LG = 18, MOD = 1e9 + 7;
const long double PI = acos(-1);
const long double EPS = 1e-7;
const int dx[] = {-1, 1, 0, 0};
const int dy[] = {0, 0, -1, 1};

int p[N], sz[N];

int get(int i) { return i == p[i] ? i : p[i] = get(p[i]); }

void mrg(int u, int v) {
    u = get(u);
    v = get(v);
    if (sz[u] > sz[v])swap(u, v);
    p[u] = v;
    sz[v] += sz[u];
}

int lo[N], hi[N];
vector<int> qr[2][N];
vector<ii> edges[N];
int a[N], b[N];

int getMid(int i) {
    return lo[i] + (hi[i] - lo[i]) / 2;
}

int ans1[N], ans2[N];

void doWork() {

    int n, m, q;
    cin >> n >> m >> q;
    f(i, 0, m) {
        int u, v, w;
        cin >> u >> v >> w;
        edges[w].push_back({u, v});
    }
    f(i, 0, q) {
        cin >> a[i] >> b[i];
        lo[i] = 0, hi[i] = 200000;
        qr[0][getMid(i)].push_back(i);
    }

    f(i, 0, 18) {
        f(j, 1, n + 1)p[j] = j, sz[j] = 1;
        f(j, 0, N) {
            for (auto [u, v]: edges[j])mrg(u, v);
            for (auto k: qr[i & 1][j]) {
                int u = a[k];
                int v = b[k];
                if (get(u) == get(v)) {
                    hi[k] = j - 1;
                    ans1[k] = j;
                    ans2[k] = sz[get(u)];
                } else {
                    lo[k] = j + 1;
                }
                qr[i & 1 ^ 1][getMid(k)].push_back(k);
            }
            qr[i & 1][j].clear();
        }
    }
    f(i, 0, q) cout << ans1[i] << ' ' << ans2[i] << '\n';
}

int32_t main() {
#ifdef ONLINE_JUDGE
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif // ONLINE_JUDGE

    int t = 1;
//    cin >> t;
    while (t--) {
        doWork();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 13ms
memory: 28212kb

input:

4 3 6
1 2 1
2 3 3
3 4 2
1 2
1 3
1 4
2 3
2 4
3 4

output:

1 2
3 4
3 4
3 4
3 4
2 2

result:

ok 6 lines

Test #2:

score: 0
Accepted
time: 410ms
memory: 75552kb

input:

200000 199999 200000
40203 148773 165038
148773 54931 77889
54931 9912 192188
9912 180491 24730
180491 77332 36976
77332 43929 146532
43929 43341 172446
43341 141304 121793
141304 105828 148202
105828 72010 107746
72010 152016 156358
152016 150074 115703
150074 117105 73900
117105 57831 59264
57831 ...

output:

165038 3
77889 2
192188 41
24730 2
36976 3
146532 4
172446 20
121793 2
148202 4
107746 2
156358 10
115703 6
73900 5
59264 2
67443 4
26999 2
156979 16
80963 3
56618 2
107615 6
63765 3
19719 2
178439 35
95141 5
72029 4
14650 2
21437 3
109944 6
139220 7
141978 9
102949 2
170997 15
100704 3
75249 2
1312...

result:

ok 200000 lines

Test #3:

score: 0
Accepted
time: 373ms
memory: 74520kb

input:

200000 199999 200000
25566 162429 116811
162429 150239 28436
150239 75366 140258
75366 176680 111452
176680 158813 50710
158813 125248 118834
125248 191706 31210
191706 163115 65321
163115 46167 44831
46167 129128 79156
129128 112971 51160
112971 195397 1773
195397 196884 159329
196884 188278 191759...

output:

116811 3
28436 2
140258 13
118834 10
118834 10
118834 10
191759 21
159329 14
79156 7
159329 14
191759 21
159329 14
159329 14
191759 21
95051 2
197843 41
46441 2
197843 41
197843 41
197843 41
197843 41
179891 15
173651 10
132452 7
179891 15
84295 3
179891 15
173651 10
179891 15
179891 15
179891 15
18...

result:

ok 200000 lines

Test #4:

score: 0
Accepted
time: 314ms
memory: 65716kb

input:

200000 199999 200000
108049 140092 177196
140092 142782 104903
142782 144052 130828
144052 105524 197299
105524 146641 105000
146641 126120 6587
126120 23329 185363
23329 145087 162872
145087 189421 141021
189421 96046 167286
96046 67072 147548
67072 7773 150238
7773 157376 141227
157376 3589 103113...

output:

199998 166739
199998 166739
199997 137953
199999 200000
199961 33049
199991 65901
199995 31759
199999 200000
199991 65901
199998 166739
199997 137953
199998 166739
199999 200000
199997 137953
199999 200000
199978 17913
199997 137953
199981 18397
199997 137953
199990 21472
199927 1556
199998 166739
1...

result:

ok 200000 lines

Test #5:

score: 0
Accepted
time: 78ms
memory: 57996kb

input:

2 1 200000
2 1 0
1 2
1 2
2 1
2 1
2 1
2 1
2 1
1 2
2 1
2 1
1 2
1 2
1 2
1 2
1 2
2 1
1 2
2 1
2 1
1 2
2 1
1 2
1 2
2 1
1 2
1 2
2 1
1 2
2 1
1 2
1 2
1 2
1 2
1 2
2 1
2 1
1 2
2 1
1 2
2 1
1 2
2 1
1 2
1 2
2 1
1 2
1 2
1 2
2 1
1 2
1 2
1 2
2 1
2 1
1 2
2 1
1 2
1 2
2 1
1 2
1 2
2 1
2 1
2 1
1 2
2 1
2 1
2 1
1 2
1 2
1 2...

output:

0 2
0 2
0 2
0 2
0 2
0 2
0 2
0 2
0 2
0 2
0 2
0 2
0 2
0 2
0 2
0 2
0 2
0 2
0 2
0 2
0 2
0 2
0 2
0 2
0 2
0 2
0 2
0 2
0 2
0 2
0 2
0 2
0 2
0 2
0 2
0 2
0 2
0 2
0 2
0 2
0 2
0 2
0 2
0 2
0 2
0 2
0 2
0 2
0 2
0 2
0 2
0 2
0 2
0 2
0 2
0 2
0 2
0 2
0 2
0 2
0 2
0 2
0 2
0 2
0 2
0 2
0 2
0 2
0 2
0 2
0 2
0 2
0 2
0 2
0 2
...

result:

ok 200000 lines

Test #6:

score: 0
Accepted
time: 46ms
memory: 59580kb

input:

2 1 200000
2 1 200000
2 1
1 2
1 2
2 1
2 1
1 2
1 2
1 2
1 2
1 2
2 1
2 1
2 1
1 2
1 2
1 2
1 2
1 2
1 2
2 1
2 1
2 1
2 1
1 2
1 2
2 1
1 2
2 1
2 1
2 1
1 2
2 1
2 1
1 2
1 2
1 2
1 2
2 1
2 1
2 1
2 1
1 2
1 2
2 1
1 2
2 1
2 1
1 2
2 1
1 2
1 2
2 1
2 1
1 2
2 1
1 2
2 1
1 2
2 1
1 2
2 1
2 1
1 2
2 1
1 2
2 1
2 1
1 2
1 2
1 ...

output:

200000 2
200000 2
200000 2
200000 2
200000 2
200000 2
200000 2
200000 2
200000 2
200000 2
200000 2
200000 2
200000 2
200000 2
200000 2
200000 2
200000 2
200000 2
200000 2
200000 2
200000 2
200000 2
200000 2
200000 2
200000 2
200000 2
200000 2
200000 2
200000 2
200000 2
200000 2
200000 2
200000 2
200...

result:

ok 200000 lines

Test #7:

score: 0
Accepted
time: 286ms
memory: 78040kb

input:

200000 199999 199999
107673 108777 137731
161326 2822 185976
42519 186329 11368
2875 128189 40207
660 17140 174600
80080 45700 24002
103478 55840 94897
141771 83861 106266
190280 61753 130887
100340 51796 36679
85897 157537 68633
179542 133431 726
4727 100325 68158
196602 138158 15657
61216 85366 13...

output:

182636 182638
188210 188212
102022 102024
92251 92253
156363 156365
56753 56755
160474 160476
43371 43373
78661 78663
102391 102393
87733 87735
50624 50626
167931 167933
163802 163804
30413 30415
9548 9550
125354 125356
66593 66595
12746 12748
172788 172790
150755 150757
175783 175785
198133 198135
...

result:

ok 199999 lines

Test #8:

score: -100
Wrong Answer
time: 196ms
memory: 65956kb

input:

632 199396 199396
528 623 151485
126 300 71970
423 596 177223
239 363 43731
126 129 43760
167 445 129222
81 349 53617
255 594 20913
222 468 187290
40 424 196898
182 202 97262
57 276 187115
20 125 84603
196 281 60208
91 159 68556
70 370 62697
64 519 173483
132 525 149142
501 581 7624
423 523 151709
9...

output:

383 42263
518 -523549419588246035
986 1153009469832036820
740 831084899163177569
391 84600
716 -1656156882450604031
312 18
439 2838942908050
530 6772650587542714291
1365 2147484674
678 831938481228373060
522 -2094197678352984131
1003 720611124755202052
498 3025396392132840018
1245 564049532289026
53...

result:

wrong answer 1st lines differ - expected: '383 254', found: '383 42263'