QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#757403#443. 翻修道路I_be_wanna100 ✓1042ms121124kbC++2013.5kb2024-11-17 06:45:392024-11-17 06:45:40

Judging History

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

  • [2024-11-17 06:45:40]
  • 评测
  • 测评结果:100
  • 用时:1042ms
  • 内存:121124kb
  • [2024-11-17 06:45:39]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define REP(i, a, b) for (int i = (a), i##_end_ = (b); i < i##_end_; ++i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()

template <typename T>
inline bool chkmin(T &a, const T &b) {
    return b < a ? a = b, 1 : 0;
}
template <typename T>
inline bool chkmax(T &a, const T &b) {
    return a < b ? a = b, 1 : 0;
}

typedef long long LL;

const int oo = 0x3f3f3f3f;

const int __buffsize = 100000;
char __buff[__buffsize];
char *__buffs, *__buffe;

#define getc()                                                                                \
    (__buffs == __buffe ? fread(__buff, 1, __buffsize, stdin), __buffe = __buff + __buffsize, \
     *((__buffs = __buff)++) : *(__buffs++))

template <typename T>
inline T &Read(T &x) {
    static char c;
    while (1) {
        c = getc();
        if (c == '-' || (c >= '0' && c <= '9'))
            break;
    }
    bool flag = c == '-';
    x = flag ? 0 : c - '0';
    while (1) {
        c = getc();
        if (c < '0' || c > '9')
            break;
        (x *= 10) += c - '0';
    }
    if (flag)
        x = -x;
    return x;
}

#undef getc

const int maxn = 500010, maxm = 1000100;

struct edge {
    int id, g, nxt;

    edge() {}
    edge(int _id, int _g, int _nxt) : id(_id), g(_g), nxt(_nxt) {}
};

int en;
int st[maxn + 5];
edge e[(maxm << 1) + 5];

inline void add_edge(int x, int y, int z) { e[en] = edge(y, z, st[x]), st[x] = en++; }

int n, m;

int S, T;

bool bad[maxn + 5];

int buffer[maxn + 5];

int dfn_cnt = 0;
int dfn[maxn + 5], low[maxn + 5];

bool has_T[maxn + 5];

void get_bad_vertices(int x) {
    if (x == T)
        has_T[x] = 1;
    dfn[x] = low[x] = dfn_cnt++;
    int cnt = 0;
    for (int i = st[x]; ~i; i = e[i].nxt) {
        int y = e[i].id;
        if (!~dfn[y]) {
            get_bad_vertices(y);
            if (has_T[y])
                has_T[x] = 1;
            if (has_T[y] || low[y] < dfn[x]) {
                cnt += buffer[x];
                chkmin(low[x], low[y]);
            }
            buffer[x] = 0;
        } else if (dfn[y] < dfn[x]) {
            ++cnt;
            ++buffer[y];
            chkmin(low[x], dfn[y]);
        }
    }
    if (cnt <= 2 && x != S && x != T) {
        bad[x] = 1;
    }
}

LL dis[maxn + 5];

bool on_path[maxm + 5];

int pathn;
int path[maxn + 5];
int id[maxn + 5];

inline void get_path() {
    static bool vis[maxn + 5];
    static int pre[maxn + 5];
    priority_queue<pair<LL, int>, vector<pair<LL, int> >, greater<pair<LL, int> > > q;
    memset(dis, oo, sizeof(dis[0]) * n);
    memset(vis, 0, sizeof(vis[0]) * n);
    q.push(mp(0, S));
    dis[S] = 0;
    while (!q.empty()) {
        int x = q.top().y;
        q.pop();
        if (vis[x])
            continue;
        vis[x] = 1;
        for (int i = st[x]; ~i; i = e[i].nxt) {
            int y = e[i].id;
            if (!bad[y] && chkmin(dis[y], dis[x] + e[i].g)) {
                pre[y] = i ^ 1;
                q.push(mp(dis[y], y));
            }
        }
    }

    memset(on_path, 0, sizeof(on_path[0]) * m);
    pathn = 0;
    int cur = T;
    while (cur != S) {
        path[pathn++] = cur;
        on_path[pre[cur] >> 1] = 1;
        cur = e[pre[cur]].id;
    }
    path[pathn++] = cur;
    reverse(path, path + pathn);

    memset(id, -1, sizeof(id[0]) * n);
    REP(i, 0, pathn) id[path[i]] = i;
}

int fa[maxn + 5];

int get(int x) { return fa[x] == x ? x : fa[x] = get(fa[x]); }

int lim[maxn + 5];

inline bool get_lim() {
    static bool leftmost[maxn + 5], rightmost[maxn + 5];
    static bool vis[maxn + 5];
    memset(leftmost, 0, sizeof(leftmost[0]) * pathn);
    memset(rightmost, 0, sizeof(rightmost[0]) * pathn);
    memset(vis, 0, sizeof(vis[0]) * n);
    REP(i, 0, pathn) {
        if (!vis[get(path[i])]) {
            leftmost[i] = 1;
            vis[get(path[i])] = 1;
        }
    }
    memset(vis, 0, sizeof(vis[0]) * n);
    for (int i = pathn - 1; i >= 0; --i) {
        if (!vis[get(path[i])]) {
            rightmost[i] = 1;
            vis[get(path[i])] = 1;
        }
    }
    if (leftmost[pathn - 1] || rightmost[0])
        return 0;
    REP(i, 0, pathn + 1) lim[i] = pathn;
    int lst = -1;
    REP(i, 0, pathn) {
        if (leftmost[i])
            lst = i;
        if (rightmost[i]) {
            if (lst > 0 && i + 1 < pathn) {
                lim[lst - 1] = i + 1;
            }
        }
    }
    for (int i = pathn - 1; i >= 0; --i) {
        chkmin(lim[i], lim[i + 1]);
    }
    return 1;
}

inline LL work() {
    static int vis[maxn + 5];
    static int info[maxn + 5];
    priority_queue<pair<LL, pair<int, int> >, vector<pair<LL, pair<int, int> > >,
                   greater<pair<LL, pair<int, int> > > >
        q;
    memset(vis, 0, sizeof(vis[0]) * n);
    q.push(mp(0, mp(S, 0)));
    while (!q.empty()) {
        LL d = q.top().x;
        int x = q.top().y.x, lst = q.top().y.y;
        q.pop();
        if (x == T) {
            return d;
        }
        if (!vis[x]) {
            info[x] = lst;
        } else if (vis[x] == 1) {
            if (~id[x]) {
                if (lim[lst] <= lim[info[x]])
                    continue;
            } else {
                if (lst >= info[x])
                    continue;
            }
        } else if (vis[x] > 1)
            continue;
        ++vis[x];
        for (int i = st[x]; ~i; i = e[i].nxt) {
            int y = e[i].id;
            if (bad[y])
                continue;
            if (~id[y]) {
                if (id[y] == lst)
                    continue;
                if (!on_path[i >> 1]) {
                    q.push(mp(d + e[i].g, mp(y, id[y])));
                } else if (id[y] < lim[lst]) {
                    q.push(mp(d + e[i].g, mp(y, lst)));
                }
            } else {
                if (~id[x])
                    q.push(mp(d + e[i].g, mp(y, id[x])));
                else
                    q.push(mp(d + e[i].g, mp(y, lst)));
            }
        }
    }
    return -1;
}

int main() { 
    Read(n), Read(m);
    memset(st, -1, sizeof(st[0]) * n), en = 0;
    REP(i, 0, m) {
        int x, y, z;
        Read(x), Read(y), Read(z), --x, --y;
        add_edge(x, y, z);
        add_edge(y, x, z);
    }
    Read(S), Read(T), --S, --T;

    memset(buffer, 0, sizeof(buffer[0]) * n);
    memset(dfn, -1, sizeof(dfn[0]) * n);
    memset(bad, 0, sizeof(bad[0]) * n);
    memset(has_T, 0, sizeof(has_T[0]) * n);
    dfn_cnt = 0;
    get_bad_vertices(S);

    get_path();

    REP(i, 0, n) fa[i] = i;
    REP(i, 0, n)
    for (int j = st[i]; ~j; j = e[j].nxt)
        if (!on_path[j >> 1])
            fa[get(i)] = get(e[j].id);

    bool not_connected = 0;
    REP(i, 0, n) if (get(i) != get(0)) {
        not_connected = 1;
        break;
    }

    if (not_connected) {
        if (!get_lim())
            printf("-1\n");
        else
            printf("%lld\n", work());
    } else
        printf("%lld\n", dis[T]);
    return 0;
}
/*#include <bits/stdc++.h>

using namespace std;

#define REP(i, a, b) for (int i = (a), i##_end_ = (b); i < i##_end_; ++i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()

template <typename T>
inline bool chkmin(T &a, const T &b) {
    return b < a ? a = b, 1 : 0;
}
template <typename T>
inline bool chkmax(T &a, const T &b) {
    return a < b ? a = b, 1 : 0;
}

typedef long long LL;

const int oo = 0x3f3f3f3f;

const int __buffsize = 100000;
char __buff[__buffsize];
char *__buffs, *__buffe;

#define getc()                                                                                \
    (__buffs == __buffe ? fread(__buff, 1, __buffsize, stdin), __buffe = __buff + __buffsize, \
     *((__buffs = __buff)++) : *(__buffs++))

template <typename T>
inline T &Read(T &x) {
    static char c;
    while (1) {
        c = getc();
        if (c == '-' || (c >= '0' && c <= '9'))
            break;
    }
    bool flag = c == '-';
    x = flag ? 0 : c - '0';
    while (1) {
        c = getc();
        if (c < '0' || c > '9')
            break;
        (x *= 10) += c - '0';
    }
    if (flag)
        x = -x;
    return x;
}

#undef getc

const int maxn = 500010, maxm = 1000100;

struct edge {
    int id, g, nxt;

    edge() {}
    edge(int _id, int _g, int _nxt) : id(_id), g(_g), nxt(_nxt) {}
};

int en;
int st[maxn + 5];
edge e[(maxm << 1) + 5];

inline void add_edge(int x, int y, int z) { e[en] = edge(y, z, st[x]), st[x] = en++; }

int n, m;

int S, T;

bool bad[maxn + 5];

int buffer[maxn + 5];

int dfn_cnt = 0;
int dfn[maxn + 5], low[maxn + 5];

bool has_T[maxn + 5];

void get_bad_vertices(int x) {
    if (x == T)
        has_T[x] = 1;
    dfn[x] = low[x] = dfn_cnt++;
    int cnt = 0;
    for (int i = st[x]; ~i; i = e[i].nxt) {
        int y = e[i].id;
        if (!~dfn[y]) {
            get_bad_vertices(y);
            if (has_T[y])
                has_T[x] = 1;
            if (has_T[y] || low[y] < dfn[x]) {
                cnt += buffer[x];
                chkmin(low[x], low[y]);
            }
            buffer[x] = 0;
        } else if (dfn[y] < dfn[x]) {
            ++cnt;
            ++buffer[y];
            chkmin(low[x], dfn[y]);
        }
    }
    if (cnt <= 2 && x != S && x != T) {
        bad[x] = 1;
    }
}

LL dis[maxn + 5];

bool on_path[maxm + 5];

int pathn;
int path[maxn + 5];
int id[maxn + 5];

inline void get_path() {
    static bool vis[maxn + 5];
    static int pre[maxn + 5];
    priority_queue<pair<LL, int>, vector<pair<LL, int> >, greater<pair<LL, int> > > q;
    memset(dis, oo, sizeof(dis[0]) * n);
    memset(vis, 0, sizeof(vis[0]) * n);
    q.push(mp(0, S));
    dis[S] = 0;
    while (!q.empty()) {
        int x = q.top().y;
        q.pop();
        if (vis[x])
            continue;
        vis[x] = 1;
        for (int i = st[x]; ~i; i = e[i].nxt) {
            int y = e[i].id;
            if (!bad[y] && chkmin(dis[y], dis[x] + e[i].g)) {
                pre[y] = i ^ 1;
                q.push(mp(dis[y], y));
            }
        }
    }

    memset(on_path, 0, sizeof(on_path[0]) * m);
    pathn = 0;
    int cur = T;
    while (cur != S) {
        path[pathn++] = cur;
        on_path[pre[cur] >> 1] = 1;
        cur = e[pre[cur]].id;
    }
    path[pathn++] = cur;
    reverse(path, path + pathn);

    memset(id, -1, sizeof(id[0]) * n);
    REP(i, 0, pathn) id[path[i]] = i;
}

int fa[maxn + 5];

int get(int x) { return fa[x] == x ? x : fa[x] = get(fa[x]); }

int lim[maxn + 5];

inline bool get_lim() {
    static bool leftmost[maxn + 5], rightmost[maxn + 5];
    static bool vis[maxn + 5];
    memset(leftmost, 0, sizeof(leftmost[0]) * pathn);
    memset(rightmost, 0, sizeof(rightmost[0]) * pathn);
    memset(vis, 0, sizeof(vis[0]) * n);
    REP(i, 0, pathn) {
        if (!vis[get(path[i])]) {
            leftmost[i] = 1;
            vis[get(path[i])] = 1;
        }
    }
    memset(vis, 0, sizeof(vis[0]) * n);
    for (int i = pathn - 1; i >= 0; --i) {
        if (!vis[get(path[i])]) {
            rightmost[i] = 1;
            vis[get(path[i])] = 1;
        }
    }
    if (leftmost[pathn - 1] || rightmost[0])
        return 0;
    REP(i, 0, pathn + 1) lim[i] = pathn;
    int lst = -1;
    REP(i, 0, pathn) {
        if (leftmost[i])
            lst = i;
        if (rightmost[i]) {
            if (lst > 0 && i + 1 < pathn) {
                lim[lst - 1] = i + 1;
            }
        }
    }
    for (int i = pathn - 1; i >= 0; --i) {
        chkmin(lim[i], lim[i + 1]);
    }
    return 1;
}

inline LL work() {
    static int vis[maxn + 5];
    static int info[maxn + 5];
    priority_queue<pair<LL, pair<int, int> >, vector<pair<LL, pair<int, int> > >,
                   greater<pair<LL, pair<int, int> > > >
        q;
    memset(vis, 0, sizeof(vis[0]) * n);
    q.push(mp(0, mp(S, 0)));
    while (!q.empty()) {
        LL d = q.top().x;
        int x = q.top().y.x, lst = q.top().y.y;
        q.pop();
        if (x == T) {
            return d;
        }
        if (!vis[x]) {
            info[x] = lst;
        } else if (vis[x] == 1) {
            if (~id[x]) {
                if (lim[lst] <= lim[info[x]])
                    continue;
            } else {
                if (lst >= info[x])
                    continue;
            }
        } else if (vis[x] > 1)
            continue;
        ++vis[x];
        for (int i = st[x]; ~i; i = e[i].nxt) {
            int y = e[i].id;
            if (bad[y])
                continue;
            if (~id[y]) {
                if (id[y] == lst)
                    continue;
                if (!on_path[i >> 1]) {
                    q.push(mp(d + e[i].g, mp(y, id[y])));
                } else if (id[y] < lim[lst]) {
                    q.push(mp(d + e[i].g, mp(y, lst)));
                }
            } else {
                if (~id[x])
                    q.push(mp(d + e[i].g, mp(y, id[x])));
                else
                    q.push(mp(d + e[i].g, mp(y, lst)));
            }
        }
    }
    return -1;
}

int main() { 
    Read(n), Read(m);
    memset(st, -1, sizeof(st[0]) * n), en = 0;
    return 0;
}*/

詳細信息


Pretests


Final Tests

Test #1:

score: 5
Accepted
time: 0ms
memory: 28752kb

input:

2000 3845
382 752 1
1749 768 362685093
192 155 200269188
1412 176 1
1236 1618 1
261 284 189019852
890 1388 1120946
233 324 3022034
1917 1771 130025452
1809 1500 1947
185 232 746253829
1137 1922 2
1191 255 11199276
1421 1442 1
1623 816 1
1280 1582 453986608
1333 1855 24686226
1619 791 524136834
1782 ...

output:

134121129003

result:

ok answer is '134121129003'

Test #2:

score: 5
Accepted
time: 0ms
memory: 26476kb

input:

2000 3813
1269 1307 277362319
16 1800 261162
619 1121 4911855
845 1628 182659018
1342 1671 523343891
43 1559 424017
1646 598 1
1235 1452 5087666
958 1430 131571568
1345 1977 10947710
885 302 666376352
1196 56 352475081
1611 677 176592008
1002 475 1
1236 1654 242172993
241 989 865
103 1180 1
215 1951...

output:

138140854400

result:

ok answer is '138140854400'

Test #3:

score: 5
Accepted
time: 0ms
memory: 26420kb

input:

2000 3823
1270 460 221408836
1032 1152 4
333 106 441182807
1087 565 132001044
1238 467 248623737
1111 1599 192202789
1161 1704 5370107
1893 1898 761361694
228 1973 1
353 571 6
1600 1780 257614452
218 750 954445005
1942 949 272727
460 1671 315826797
279 604 1
1586 1549 182175601
1275 4 8731
1006 575 ...

output:

134118694716

result:

ok answer is '134118694716'

Test #4:

score: 5
Accepted
time: 0ms
memory: 30588kb

input:

2000 3825
1068 852 270912535
242 1849 181978822
153 1952 10004
1847 1247 353762544
439 1953 175213656
1516 31 768392654
1701 1725 18697901
1241 310 188712734
1707 377 113778691
1630 459 2
488 361 242496365
1558 1667 11545
841 174 17711495
1240 1978 227924190
620 166 4
1963 1845 107272881
621 99 24
1...

output:

135181884998

result:

ok answer is '135181884998'

Test #5:

score: 5
Accepted
time: 0ms
memory: 26368kb

input:

2000 3828
1933 718 739678288
1147 497 195051551
228 1307 1
293 237 2
752 1106 976566039
1135 544 395818768
67 43 1
461 1993 38863780
1942 25 643685291
1542 630 150325791
247 167 38129947
684 1874 1
239 212 4
430 372 6319
1786 1951 73672621
221 1474 58774856
834 261 2730
144 1413 1
996 595 958104736
...

output:

133250447316

result:

ok answer is '133250447316'

Test #6:

score: 5
Accepted
time: 2ms
memory: 26500kb

input:

2000 3831
745 1025 72660523
17 1923 78369483
1739 210 615012778
148 1675 90932234
1676 1197 129874536
1500 1142 44945436
217 386 284154
1712 1268 240818882
533 1468 320
1530 753 492797879
765 1353 54317386
1520 1552 2109786
1846 1507 142535218
1835 1304 134772621
921 205 224272187
715 195 4504351
22...

output:

134653840656

result:

ok answer is '134653840656'

Test #7:

score: 5
Accepted
time: 217ms
memory: 69900kb

input:

500000 889698
412220 407980 499428456
158832 239591 499428456
182707 117557 499428456
214936 123420 499428456
365872 181112 499428456
30686 198797 499428456
312244 385027 499428456
284487 46167 499428456
217227 443514 499428456
347857 111938 499428456
108078 492305 499428456
162160 148152 499428456
...

output:

-1

result:

ok answer is '-1'

Test #8:

score: 5
Accepted
time: 208ms
memory: 67960kb

input:

500000 889666
88463 342604 382544584
50508 395252 382544584
128944 42145 382544584
142177 278396 382544584
403758 1554 382544584
362313 245693 382544584
337218 91514 382544584
2820 149982 382544584
475533 212931 382544584
277184 397094 382544584
484709 87632 382544584
101778 452812 382544584
31619 4...

output:

53147301599704

result:

ok answer is '53147301599704'

Test #9:

score: 5
Accepted
time: 197ms
memory: 66768kb

input:

500000 889500
17217 253061 855595304
304789 334990 855595304
330105 53808 855595304
24564 218408 855595304
121664 490479 855595304
250105 234943 855595304
99628 83788 855595304
36542 384892 855595304
290146 56887 855595304
415420 88878 855595304
250575 370062 855595304
245581 15004 855595304
133273 ...

output:

118695880928616

result:

ok answer is '118695880928616'

Test #10:

score: 5
Accepted
time: 202ms
memory: 67748kb

input:

500000 889582
454310 375253 738711432
124500 417665 738711432
303268 163821 738711432
375036 459659 738711432
301583 368655 738711432
438271 391586 738711432
82908 376663 738711432
123789 325867 738711432
197623 238951 738711432
253554 409791 738711432
488826 81355 738711432
429142 157251 738711432
...

output:

102610711461960

result:

ok answer is '102610711461960'

Test #11:

score: 5
Accepted
time: 795ms
memory: 121124kb

input:

500000 970996
159170 122348 1
280902 145846 1
306211 24651 1
88424 333838 1
322035 119018 1
1610 393965 1
204248 294711 358492490
288255 203073 1
71527 147298 123453960
492803 5795 223
229170 146455 1
463197 345469 1
163991 428079 1
359263 51301 1
421528 227565 957
46453 250036 1
487873 113177 1
486...

output:

5860994850909

result:

ok answer is '5860994850909'

Test #12:

score: 5
Accepted
time: 896ms
memory: 99992kb

input:

500000 971032
115783 252285 1
465444 224227 6
217615 122881 1
212250 340359 1
381692 26753 27904
429751 27996 538682339
229314 469878 1
7985 40852 1
277746 199722 1
279251 57570 1
274638 187821 1
9222 335353 1
84220 185452 1
82420 97974 114118
337199 445497 14820
442671 73197 7995
328727 40707 82640...

output:

5979754647875

result:

ok answer is '5979754647875'

Test #13:

score: 5
Accepted
time: 1042ms
memory: 111912kb

input:

500000 970905
95485 91092 1
372030 437825 1
311904 227741 487554784
420925 492435 1
171872 335733 1
413562 275040 1
48577 117737 1
313317 386004 360250873
251801 56752 850411041
176471 193862 773
377095 429850 1
231630 107647 283939492
52019 395817 1
355988 421294 869718039
64841 118126 979910530
44...

output:

5913452707639

result:

ok answer is '5913452707639'

Test #14:

score: 5
Accepted
time: 1014ms
memory: 112976kb

input:

500000 970992
94750 47862 641272697
173456 220989 1
34685 113862 4
116058 99494 1
102996 191245 186350796
143392 175541 9
166102 68291 911510828
175503 199733 909168328
354558 469817 288579804
354527 110456 1
263220 253494 326018395
140412 448661 1
301473 343155 706602971
149351 457770 1
337053 2923...

output:

5898999991008

result:

ok answer is '5898999991008'

Test #15:

score: 5
Accepted
time: 1027ms
memory: 112660kb

input:

500000 970852
137047 205324 1
312328 35828 1
242221 383587 427593843
142623 184077 309394906
208198 90167 922782015
156619 477588 14944666
151572 446806 1
326606 134904 1
465271 37039 1
266406 125472 1
122953 464090 379
41712 362091 1
424327 302149 1
424465 107198 206627661
103964 67048 163
101342 4...

output:

6018366516551

result:

ok answer is '6018366516551'

Test #16:

score: 5
Accepted
time: 455ms
memory: 71888kb

input:

500000 959403
6507 367806 850341350
36869 59690 67
20756 268956 425995925
384478 127906 2
364049 100536 1
369975 153712 19400997
117523 265664 1
457574 23 805942267
482455 389707 160636821
298125 142295 206942709
289174 51593 56763439
432878 313640 249061366
400416 390030 4
487587 35240 972671972
76...

output:

33280951789769

result:

ok answer is '33280951789769'

Test #17:

score: 5
Accepted
time: 464ms
memory: 71764kb

input:

500000 959429
65141 71416 110109451
92695 83799 6
266981 421290 449719409
4938 23167 1
335697 357809 247869044
43040 223964 2
388744 26145 1
440267 74224 28482479
253309 298986 67897188
481999 181973 1
366665 153587 752798493
340278 421171 89443207
193320 53820 1
11495 67348 54041386
343103 273144 1...

output:

33280871544058

result:

ok answer is '33280871544058'

Test #18:

score: 5
Accepted
time: 471ms
memory: 71896kb

input:

500000 959224
311045 74231 654
2450 321772 52033
490860 219449 1
182619 154257 35502539
339285 169887 123648903
443080 351262 134321942
56933 44672 332954176
14064 332642 1
443040 165457 24594891
62438 234761 129992922
494078 89935 1
142211 432787 106388739
10039 4791 138147678
225152 116732 1310709...

output:

33339043614821

result:

ok answer is '33339043614821'

Test #19:

score: 5
Accepted
time: 422ms
memory: 72520kb

input:

500000 959433
99510 267488 112661190
355351 358725 65050330
399590 317864 13
198999 367969 475485612
159372 167207 65208983
430286 328666 476390860
4325 349167 2
20161 223579 346649178
480983 317598 272193902
29296 251581 105470410
493625 346440 45
393054 281607 215047915
225199 188080 199076839
727...

output:

33255817749539

result:

ok answer is '33255817749539'

Test #20:

score: 5
Accepted
time: 417ms
memory: 72508kb

input:

500000 959659
217672 276229 6
329164 411970 135170666
342422 146298 391789563
474689 165546 217874734
402611 225401 6825828
186743 227563 12
67384 114722 4
448351 237508 1
174763 496208 1
206819 211755 3
91807 19129 114701350
446246 324623 192
100550 16128 327840431
492398 362096 436
126305 122021 1...

output:

33290733109033

result:

ok answer is '33290733109033'

Extra Test:

score: 0
Extra Test Passed