Submission #28328

# Submission time Handle Problem Language Result Execution time Memory
28328 2017-07-16T04:45:07 Z /*Sn*/(#1133, jjwdi0) Alternative Mart (FXCUP2_mart) C++11
1 / 1
1709 ms 61808 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

struct Z { int x, y, c; } T[80003];
struct Q {
    int x, st;
    ll c;
    Q(int _x, int _st, ll _c) { x = _x, st = _st, c = _c; }
    bool operator < (const Q &A) const { return c == A.c ? st < A.st : c < A.c; }
    bool operator > (const Q &A) const { return c == A.c ? st > A.st : c > A.c; }
};

int N, M, K, _Q;
vector<int> v[50003];
bool mart[50003];
ll D[50003][12];
int num[50003][12], idx[50003];
int q[13];
priority_queue<Q, vector<Q>, greater<Q>> pq;

int main() {
    scanf("%d %d %d %d", &N, &M, &K, &_Q);
    for(int i=0, x; i<K; i++) scanf("%d", &x), mart[x] = 1;
    for(int i=0; i<M; i++) {
        scanf("%d %d %d", &T[i].x, &T[i].y, &T[i].c);
        v[T[i].x].push_back(i);
        v[T[i].y].push_back(i);
    }
    for(int i=1; i<=N; i++) for(int j=1; j<=11; j++) D[i][j] = 1e15;
    for(int i=1; i<=N; idx[i] = 1, i++) if(mart[i]) pq.push(Q(i, i, 0));
    while(!pq.empty()) {
        int u = pq.top().x, st = pq.top().st; ll cost = pq.top().c; pq.pop();
        int id = idx[u];
        if(id > 11) continue;
        bool chk = 0;
        for(int i=1; i<=id; i++) if(num[u][i] == st) chk = 1;
        if(chk) continue;
        num[u][id] = st, idx[u]++, D[u][id] = cost;
        for(int it : v[u]) {
            int ne = T[it].x == u ? T[it].y : T[it].x;
            ll c = T[it].c;
            pq.push(Q(ne, st, c + cost));
        }
    }
    for(int i=0; i<_Q; i++) {
        int s, x;
        scanf("%d %d", &s, &x);
        for(int j=0; j<x; j++) scanf("%d", q+j);
        for(int j=1; j<=11; j++) {
            bool chk = 0;
            for(int k=0; k<x; k++) if(q[k] == num[s][j]) chk = 1;
            if(chk == 0) { printf("%d %lld\n", num[s][j], D[s][j]); break; }
        }
    }
}

Compilation message

mart.cpp: In function 'int main()':
mart.cpp:23:42: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d %d %d", &N, &M, &K, &_Q);
                                          ^
mart.cpp:24:59: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i=0, x; i<K; i++) scanf("%d", &x), mart[x] = 1;
                                                           ^
mart.cpp:26:53: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d %d", &T[i].x, &T[i].y, &T[i].c);
                                                     ^
mart.cpp:48:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &s, &x);
                               ^
mart.cpp:49:48: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         for(int j=0; j<x; j++) scanf("%d", q+j);
                                                ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 11408 KB Output is correct
2 Correct 0 ms 11408 KB Output is correct
3 Correct 0 ms 11408 KB Output is correct
4 Correct 0 ms 11408 KB Output is correct
5 Correct 0 ms 11552 KB Output is correct
6 Correct 0 ms 11552 KB Output is correct
7 Correct 3 ms 11564 KB Output is correct
8 Correct 3 ms 11408 KB Output is correct
9 Correct 103 ms 17820 KB Output is correct
10 Correct 79 ms 17820 KB Output is correct
11 Correct 43 ms 12036 KB Output is correct
12 Correct 19 ms 11672 KB Output is correct
13 Correct 1479 ms 61804 KB Output is correct
14 Correct 1236 ms 61808 KB Output is correct
15 Correct 106 ms 13492 KB Output is correct
16 Correct 113 ms 12992 KB Output is correct
17 Correct 426 ms 16180 KB Output is correct
18 Correct 373 ms 12992 KB Output is correct
19 Correct 616 ms 16184 KB Output is correct
20 Correct 406 ms 12992 KB Output is correct
21 Correct 783 ms 19256 KB Output is correct
22 Correct 483 ms 13436 KB Output is correct
23 Correct 916 ms 25396 KB Output is correct
24 Correct 893 ms 19200 KB Output is correct
25 Correct 943 ms 25400 KB Output is correct
26 Correct 953 ms 19200 KB Output is correct
27 Correct 139 ms 14696 KB Output is correct
28 Correct 96 ms 13828 KB Output is correct
29 Correct 966 ms 19300 KB Output is correct
30 Correct 596 ms 16128 KB Output is correct
31 Correct 1049 ms 25420 KB Output is correct
32 Correct 716 ms 16128 KB Output is correct
33 Correct 1039 ms 19268 KB Output is correct
34 Correct 1316 ms 25396 KB Output is correct
35 Correct 859 ms 25420 KB Output is correct
36 Correct 1283 ms 25364 KB Output is correct
37 Correct 1526 ms 37768 KB Output is correct
38 Correct 1343 ms 37664 KB Output is correct
39 Correct 159 ms 14832 KB Output is correct
40 Correct 166 ms 14768 KB Output is correct
41 Correct 1496 ms 25584 KB Output is correct
42 Correct 1459 ms 25524 KB Output is correct
43 Correct 1659 ms 37868 KB Output is correct
44 Correct 1573 ms 37808 KB Output is correct
45 Correct 1709 ms 37876 KB Output is correct
46 Correct 1663 ms 37812 KB Output is correct
47 Correct 1676 ms 37872 KB Output is correct
48 Correct 1696 ms 37808 KB Output is correct
49 Correct 1633 ms 37876 KB Output is correct
50 Correct 1676 ms 37812 KB Output is correct
51 Correct 896 ms 37872 KB Output is correct
52 Correct 959 ms 37812 KB Output is correct
53 Correct 259 ms 12992 KB Output is correct
54 Correct 1329 ms 25384 KB Output is correct
55 Correct 1106 ms 25456 KB Output is correct
56 Correct 1583 ms 37808 KB Output is correct
57 Correct 1556 ms 61612 KB Output is correct