답안 #14720

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
14720 2015-06-13T09:22:08 Z gs14004 약속장소 정하기 (GCJ12KOR_appointment) C++14
컴파일 오류
0 ms 0 KB
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>
#include <algorithm>
using namespace std;
typedef pair<int,int> pi;

int cand[10005][105];
vector<pi> graph[10005];

int n, p, m;
int st[105], vel[105];
bool vis[10005];

void solve(){
    scanf("%d %d %d",&n,&p,&m);
    for (int i=1; i<=n; i++) {
        graph[i].clear();
        fill(cand,cand+105,(1<<31) - 1);
    }
    for (int i=1; i<=p; i++) {
        scanf("%d %d",&st[i],&vel[i]);
    }
    for (int i=0; i<m; i++) {
        int d, t, s;
        scanf("%d %d %d",&d,&t,&s);
        for (int j=1; j<t; j++) {
            int u;
            scanf("%d",&u);
            graph[s].push_back(pi(d,u));
            graph[u].push_back(pi(d,s));
            s = u;
        }
    }
    priority_queue<pi,vector<pi>,greater<pi> > pq;
    for (int i=1; i<=p; i++) {
        memset(vis,0,sizeof(vis));
        pq.push(pi(0,st[i]));
        while (!pq.empty()) {
            pi t = pq.top();
            pq.pop();
            if(vis[t.second]) continue;
            vis[t.second] = 1;
            cand[t.second][i] = t.first * vel[i];
            for (auto &j : graph[t.second]){
                if(vis[j.second] || cand[j.second][i] < cand[t.second][i] + t.first) continue;
                cand[j.second][i] = cand[t.second][i] + t.first;
                pq.push(pi(j.first + t.first,j.second));
            }
        }
    }
    int pos = -1, posv = 2e9;
    for (int i=1; i<=n; i++) {
        int mv = *max_element(cand[i] + 1, cand[i] + p + 1);
        if(posv > mv) {
            posv = mv;
            pos = i;
        }
    }
    if(pos == -1) posv = -1;
    printf("%d",posv);
}

int main(){
    int t;
    scanf("%d",&t);
    for (int i=1; i<=t; i++) {
        printf("Case #%d: ",i);
        solve();
        puts("");
    }
}

Compilation message

C.cpp: In function ‘void solve()’:
C.cpp:20:36: warning: integer overflow in expression [-Woverflow]
         fill(cand,cand+105,(1<<31) - 1);
                                    ^
In file included from /usr/include/c++/4.9/deque:60:0,
                 from /usr/include/c++/4.9/queue:60,
                 from C.cpp:3:
/usr/include/c++/4.9/bits/stl_algobase.h: In instantiation of ‘typename __gnu_cxx::__enable_if<std::__is_scalar<_Tp>::__value, void>::__type std::__fill_a(_ForwardIterator, _ForwardIterator, const _Tp&) [with _ForwardIterator = int (*)[105]; _Tp = int; typename __gnu_cxx::__enable_if<std::__is_scalar<_Tp>::__value, void>::__type = void]’:
/usr/include/c++/4.9/bits/stl_algobase.h:740:14:   required from ‘void std::fill(_ForwardIterator, _ForwardIterator, const _Tp&) [with _ForwardIterator = int (*)[105]; _Tp = int]’
C.cpp:20:39:   required from here
/usr/include/c++/4.9/bits/stl_algobase.h:704:11: error: incompatible types in assignment of ‘const int’ to ‘int [105]’
  *__first = __tmp;
           ^
C.cpp:17:31: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d %d",&n,&p,&m);
                               ^
C.cpp:23:38: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d",&st[i],&vel[i]);
                                      ^
C.cpp:27:35: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d %d",&d,&t,&s);
                                   ^
C.cpp:30:27: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d",&u);
                           ^
C.cpp: In function ‘int main()’:
C.cpp:67:19: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&t);
                   ^