Submission #28429

# Submission time Handle Problem Language Result Execution time Memory
28429 2017-07-16T05:44:10 Z 일단아무거나적어놓은팀이름(#1191, solarmagic, junodeveloper) Alternative Mart (FXCUP2_mart) C++14
1 / 1
2103 ms 68580 KB
#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
#include<set>
using namespace std;
typedef long long ll;
int n, m, k, q;
int martIdx[50001];
set<int> visited[50001];
vector<pair<ll,int> > dist[50001];
vector<pair<int,ll> > adj[50001];
void dijkstra() {
    priority_queue<pair<ll, pair<int, int> > > q;
    for(int i = 0; i < k; ++i)
        q.push({0, {-martIdx[i], martIdx[i]}});
    while(!q.empty()) {
        int u = q.top().second.second;
        int from = -q.top().second.first;
        ll c = -q.top().first; q.pop();
        if(visited[u].size() == 11 || visited[u].find(from) != visited[u].end()) continue;
        visited[u].insert(from);
        dist[u].push_back({c, from});
        for(auto& t : adj[u]) {
            int to = t.first;
            ll cost = t.second;
            q.push({-(c + cost), {-from, to}});
        }
    }
}
int main() {
    scanf("%d%d%d%d", &n, &m, &k, &q);
    for(int i = 0; i < k; ++i) scanf("%d", martIdx + i);
    for(int i = 0; i < m; ++i) {
        int a, b, v;
        scanf("%d%d%d", &a, &b, &v);
        adj[a].push_back({b, v});
        adj[b].push_back({a, v});
    }
    dijkstra();
    for(int i = 0; i < q; ++i) {
        int s, x;
        scanf("%d%d", &s, &x);
        ll mn = 1e18, rIdx = 1e18;
        bool closed[11] = {0};
        for(int j = 0, idx; j < x; ++j) {
            scanf("%d", &idx);
            for(int l = 0; l < dist[s].size(); ++l)
                if(dist[s][l].second == idx) closed[l] = 1;
        }
        for(int j = 0; j < dist[s].size(); ++j) {
            if(closed[j]) continue;
            if(dist[s][j].first < mn || (dist[s][j].first == mn && dist[s][j].second < rIdx)) {
                mn = dist[s][j].first;
                rIdx = dist[s][j].second;
            }
        }
        printf("%lld %lld\n", rIdx, mn);
    }
    return 0;
}

/*
4 5 2 4
1 4
1 2 5
2 4 5
4 3 5
3 1 5
2 3 1
3 0
1 1 1
2 1 4
4 0
*/

Compilation message

mart.cpp: In function 'int main()':
mart.cpp:48:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for(int l = 0; l < dist[s].size(); ++l)
                              ^
mart.cpp:51:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j = 0; j < dist[s].size(); ++j) {
                          ^
mart.cpp:32:38: 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:33:56: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i = 0; i < k; ++i) scanf("%d", martIdx + i);
                                                        ^
mart.cpp:36:36: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%d", &a, &b, &v);
                                    ^
mart.cpp:43:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &s, &x);
                              ^
mart.cpp:47:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d", &idx);
                              ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 6908 KB Output is correct
2 Correct 0 ms 6908 KB Output is correct
3 Correct 0 ms 6908 KB Output is correct
4 Correct 0 ms 6908 KB Output is correct
5 Correct 0 ms 7056 KB Output is correct
6 Correct 0 ms 7056 KB Output is correct
7 Correct 3 ms 7436 KB Output is correct
8 Correct 6 ms 7304 KB Output is correct
9 Correct 86 ms 13844 KB Output is correct
10 Correct 69 ms 13832 KB Output is correct
11 Correct 59 ms 11396 KB Output is correct
12 Correct 56 ms 11136 KB Output is correct
13 Correct 943 ms 62280 KB Output is correct
14 Correct 723 ms 62300 KB Output is correct
15 Correct 116 ms 13652 KB Output is correct
16 Correct 123 ms 13244 KB Output is correct
17 Correct 1036 ms 48692 KB Output is correct
18 Correct 809 ms 47300 KB Output is correct
19 Correct 1239 ms 51200 KB Output is correct
20 Correct 1012 ms 49544 KB Output is correct
21 Correct 1269 ms 53380 KB Output is correct
22 Correct 1269 ms 49728 KB Output is correct
23 Correct 1406 ms 58272 KB Output is correct
24 Correct 1516 ms 54356 KB Output is correct
25 Correct 1369 ms 58668 KB Output is correct
26 Correct 1459 ms 54876 KB Output is correct
27 Correct 169 ms 15104 KB Output is correct
28 Correct 156 ms 14288 KB Output is correct
29 Correct 1823 ms 51676 KB Output is correct
30 Correct 1489 ms 49352 KB Output is correct
31 Correct 1476 ms 57768 KB Output is correct
32 Correct 1313 ms 51468 KB Output is correct
33 Correct 1256 ms 53524 KB Output is correct
34 Correct 1376 ms 58396 KB Output is correct
35 Correct 1479 ms 58608 KB Output is correct
36 Correct 1553 ms 58964 KB Output is correct
37 Correct 1629 ms 67820 KB Output is correct
38 Correct 1623 ms 67644 KB Output is correct
39 Correct 189 ms 15740 KB Output is correct
40 Correct 189 ms 15780 KB Output is correct
41 Correct 2045 ms 56424 KB Output is correct
42 Correct 2103 ms 56600 KB Output is correct
43 Correct 1753 ms 66860 KB Output is correct
44 Correct 1813 ms 67024 KB Output is correct
45 Correct 1849 ms 66868 KB Output is correct
46 Correct 1726 ms 66992 KB Output is correct
47 Correct 1936 ms 67784 KB Output is correct
48 Correct 1813 ms 67660 KB Output is correct
49 Correct 1709 ms 68180 KB Output is correct
50 Correct 1876 ms 68188 KB Output is correct
51 Correct 1556 ms 68444 KB Output is correct
52 Correct 1506 ms 68580 KB Output is correct
53 Correct 473 ms 48628 KB Output is correct
54 Correct 1553 ms 57912 KB Output is correct
55 Correct 1599 ms 57980 KB Output is correct
56 Correct 1933 ms 66744 KB Output is correct
57 Correct 959 ms 60844 KB Output is correct