Submission #1055727

# Submission time Handle Problem Language Result Execution time Memory
1055727 2024-08-13T04:33:15 Z 캐나다 선발고사 레전드(#11109) Treasure Hunt (CCO24_day1problem1) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;

int n,m;
typedef pair<int,int> P;
vector<P> adj[1000005];
int arr[1000005];
bool save[1000005];

int main(void) {
    scanf("%d %d",&n,&m);
    vector<P> v;
    for(int i=1;i<=n;i++) {
        scanf("%d",&arr[i]);
        v.push_back(P(arr[i],i));
    }
    for(int i=0;i<m;i++) {
        int u,v,w;
        scanf("%d %d %d",&u,&v,&w);
        adj[u].push_back(P(v,w));
        adj[v].push_back(P(u,w));
    }
    sort(v.begin(),v.end());
    reverse(v.begin(),v.end());
    for(int i=0;i<v.size();i++) {
        int now=v[i];
        save[now]=true;
        for(int j=0;j<adj[now].size();j++) {
            int nt=adj[now][j].first;
            if (save[nt]) {
                arr[now]=max(arr[now],arr[nt]-adj[now][j].second);
            }
        }
    }
    for(int i=1;i<=n;i++) {
        printf("%d\n",arr[i]);
    }
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:25:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |     for(int i=0;i<v.size();i++) {
      |                 ~^~~~~~~~~
Main.cpp:26:20: error: cannot convert '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'std::pair<int, int>'} to 'int' in initialization
   26 |         int now=v[i];
      |                    ^
Main.cpp:28:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |         for(int j=0;j<adj[now].size();j++) {
      |                     ~^~~~~~~~~~~~~~~~
Main.cpp:11:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |     scanf("%d %d",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~~
Main.cpp:14:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |         scanf("%d",&arr[i]);
      |         ~~~~~^~~~~~~~~~~~~~
Main.cpp:19:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |         scanf("%d %d %d",&u,&v,&w);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~