답안 #28611

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
28611 2017-07-16T07:59:13 Z 맞왜틀 맞왜틀 신나는노래~ 헤이! 나도한번 불러보자(#1216, skdudn321, choiking10) Alternative Mart (FXCUP2_mart) C++11
0 / 1
4143 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);
                           ^
# 결과 실행 시간 메모리 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 3 ms 3524 KB Output is correct
7 Correct 9 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 59 ms 8504 KB Output is correct
11 Correct 116 ms 5956 KB Output is correct
12 Correct 79 ms 5248 KB Output is correct
13 Correct 2586 ms 154224 KB Output is correct
14 Correct 2969 ms 154232 KB Output is correct
15 Correct 119 ms 7160 KB Output is correct
16 Correct 96 ms 6692 KB Output is correct
17 Correct 696 ms 14640 KB Output is correct
18 Correct 509 ms 12896 KB Output is correct
19 Correct 2193 ms 25712 KB Output is correct
20 Correct 1456 ms 19760 KB Output is correct
21 Correct 2236 ms 25684 KB Output is correct
22 Correct 1863 ms 19944 KB Output is correct
23 Correct 2343 ms 31996 KB Output is correct
24 Correct 2276 ms 22912 KB Output is correct
25 Correct 2229 ms 31996 KB Output is correct
26 Correct 2316 ms 22912 KB Output is correct
27 Correct 146 ms 7936 KB Output is correct
28 Correct 159 ms 7380 KB Output is correct
29 Correct 973 ms 16684 KB Output is correct
30 Correct 826 ms 14724 KB Output is correct
31 Correct 2873 ms 32004 KB Output is correct
32 Correct 2223 ms 22580 KB Output is correct
33 Correct 2409 ms 31880 KB Output is correct
34 Correct 2999 ms 51432 KB Output is correct
35 Correct 2719 ms 32128 KB Output is correct
36 Correct 3553 ms 52748 KB Output is correct
37 Correct 3409 ms 48920 KB Output is correct
38 Correct 3229 ms 51560 KB Output is correct
39 Correct 213 ms 8296 KB Output is correct
40 Correct 176 ms 8296 KB Output is correct
41 Correct 1339 ms 20004 KB Output is correct
42 Correct 1233 ms 20148 KB Output is correct
43 Correct 3869 ms 48492 KB Output is correct
44 Correct 3989 ms 49816 KB Output is correct
45 Correct 3669 ms 48140 KB Output is correct
46 Correct 3119 ms 49472 KB Output is correct
47 Correct 3763 ms 48260 KB Output is correct
48 Correct 3873 ms 49184 KB Output is correct
49 Correct 3986 ms 48260 KB Output is correct
50 Correct 4143 ms 49184 KB Output is correct
51 Incorrect 2393 ms 89744 KB Output isn't correct
52 Halted 0 ms 0 KB -