Submission #28630

# Submission time Handle Problem Language Result Execution time Memory
28630 2017-07-16T08:13:23 Z 맞왜틀 맞왜틀 신나는노래~ 헤이! 나도한번 불러보자(#1216, skdudn321, choiking10) Alternative Mart (FXCUP2_mart) C++11
1 / 1
3836 ms 154232 KB
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <algorithm>
std::vector<std::pair<int,int>> G[50010];
std::vector<std::pair<int,int>> CK[50010];
struct node{
    int v, id, from;
};
bool operator<(node n1, node n2){
    return std::make_pair(-n1.v,-n1.from) < std::make_pair(-n2.v,-n2.from);
}
int main(){
    int N,M,K,Q;
    scanf("%d%d%d%d",&N,&M,&K,&Q);
    std::priority_queue<node> q;
    for(int i =0 ; i< K;i++){
        int v;
        scanf("%d",&v);
        q.push({0,v,v});
    }
    for(int i = 0; i < M ; i++){
        int A,B,C;
        scanf("%d%d%d",&A,&B,&C);
        G[A].push_back({B,C});
        G[B].push_back({A,C});
    }
    while(q.size() != 0){
        auto t = q.top();
        q.pop();
        if(CK[t.id].size() > 30) continue;
        bool flag = false;
        for(auto i : CK[t.id]){
            if(i.second == t.from) {
                flag = true;
                break;
            }
        }
        if(flag) continue;
        CK[t.id].push_back({t.v,t.from});

        for(auto i : G[t.id]){
            q.push({t.v+i.second,i.first,t.from});
        }
    }
    for(int i =0 ; i < Q;i ++){
        int S, X;
        scanf("%d%d",&S,&X);
        std::set<int> PC;
        for(int j =0; j < X; j++){
            int v;
            scanf("%d",&v);
            PC.insert(v);
        }
        std::sort(CK[S].begin(),CK[S].end());
        
        for(auto j : CK[S]){
            if(!PC.count(j.second)){
                printf("%d %d\n",j.second,j.first);
                break;
            }
        }
    }
}

Compilation message

mart.cpp: In function 'int main()':
mart.cpp:16:34: 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:20:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&v);
                       ^
mart.cpp:25:33: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%d",&A,&B,&C);
                                 ^
mart.cpp:49:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d",&S,&X);
                            ^
mart.cpp:53:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d",&v);
                           ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 3524 KB Output is correct
2 Correct 0 ms 3524 KB Output is correct
3 Correct 0 ms 3524 KB Output is correct
4 Correct 0 ms 3524 KB Output is correct
5 Correct 3 ms 3524 KB Output is correct
6 Correct 0 ms 3524 KB Output is correct
7 Correct 3 ms 3832 KB Output is correct
8 Correct 6 ms 3656 KB Output is correct
9 Correct 296 ms 22336 KB Output is correct
10 Correct 56 ms 8504 KB Output is correct
11 Correct 113 ms 5956 KB Output is correct
12 Correct 83 ms 5248 KB Output is correct
13 Correct 3203 ms 154224 KB Output is correct
14 Correct 3069 ms 154232 KB Output is correct
15 Correct 119 ms 7160 KB Output is correct
16 Correct 99 ms 6692 KB Output is correct
17 Correct 746 ms 14640 KB Output is correct
18 Correct 466 ms 12896 KB Output is correct
19 Correct 2439 ms 25712 KB Output is correct
20 Correct 1563 ms 19760 KB Output is correct
21 Correct 2286 ms 25684 KB Output is correct
22 Correct 1906 ms 19944 KB Output is correct
23 Correct 2609 ms 31996 KB Output is correct
24 Correct 2443 ms 22912 KB Output is correct
25 Correct 2486 ms 31996 KB Output is correct
26 Correct 2406 ms 22912 KB Output is correct
27 Correct 149 ms 7936 KB Output is correct
28 Correct 136 ms 7380 KB Output is correct
29 Correct 986 ms 16552 KB Output is correct
30 Correct 823 ms 14724 KB Output is correct
31 Correct 2713 ms 32004 KB Output is correct
32 Correct 2443 ms 22580 KB Output is correct
33 Correct 2573 ms 31880 KB Output is correct
34 Correct 3569 ms 51432 KB Output is correct
35 Correct 2893 ms 32128 KB Output is correct
36 Correct 3133 ms 52748 KB Output is correct
37 Correct 3509 ms 48920 KB Output is correct
38 Correct 3196 ms 51560 KB Output is correct
39 Correct 173 ms 8296 KB Output is correct
40 Correct 179 ms 8296 KB Output is correct
41 Correct 1326 ms 20004 KB Output is correct
42 Correct 1283 ms 20144 KB Output is correct
43 Correct 3833 ms 48492 KB Output is correct
44 Correct 3743 ms 49816 KB Output is correct
45 Correct 3756 ms 48140 KB Output is correct
46 Correct 3716 ms 49472 KB Output is correct
47 Correct 3703 ms 48260 KB Output is correct
48 Correct 3389 ms 49184 KB Output is correct
49 Correct 2866 ms 48260 KB Output is correct
50 Correct 2783 ms 49184 KB Output is correct
51 Correct 1703 ms 89612 KB Output is correct
52 Correct 1876 ms 91460 KB Output is correct
53 Correct 649 ms 18440 KB Output is correct
54 Correct 2299 ms 52972 KB Output is correct
55 Correct 2359 ms 49480 KB Output is correct
56 Correct 3836 ms 49060 KB Output is correct
57 Correct 1996 ms 79464 KB Output is correct