제출 #29188

#제출 시각아이디문제언어결과실행 시간메모리
29188junodeveloperAlternative Mart (FXCUP2_mart)C++14
1 / 1
2306 ms68580 KiB
#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;
}

컴파일 시 표준 에러 (stderr) 메시지

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 timeMemoryGrader output
Fetching results...