답안 #28463

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
28463 2017-07-16T06:14:47 Z not good but never sad(#1132, kriii) Alternative Mart (FXCUP2_mart) C++
컴파일 오류
0 ms 0 KB
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;

struct phase{
	int s,x,c;
	bool operator <(const phase &t) const{return c > t.c;}
};
priority_queue<phase> Q;
map<int, int> dist[50505];

vector<pair<int, int> > G[50505];
int N,M,K,q;

pair<int, int> mx(map<int, int> &m)
{
	pair<int, int> ret;
	for (auto &p : m){
		ret = max(ret,{p.second,p.first});
	}
	return ret;
}

int main()
{
	scanf ("%d %d %d %d",&N,&M,&K,&q);
	for (int i=0;i<K;i++){
		int x; scanf ("%d",&x);
		dist[x][x] = 0;
		Q.push({x,x,0});
	}

	for (int i=0;i<M;i++){
		int x,y,c;
		scanf ("%d %d %d",&x,&y,&c);
		G[x].push_back({y,c});
		G[y].push_back({x,c});
	}

	while (!Q.empty()){
		int s = Q.top().s, x = Q.top().x, c = Q.top().c; Q.pop();
		if (!dist[x].count(s) || dist[x][s] != c) continue;
		for (auto &p : G[x]){
			int y = p.first;
			int nc = c + p.second;
			if (dist[y].count(s) && dist[y][s] <= nc) continue;
			if (dist[y].size() < 12 || mx(dist[y]) > make_pair(nc,s)){
				dist[y][s] = nc;
				if (dist[y].size() == 12){
					auto p = mx(dist[y]);
					dist[y].erase(p.second);
				}
				Q.push({s,y,nc});
			}
		}
	}

	while (q--){
		int x,n;
		set<int> chk;
		scanf ("%d %d",&x,&n); while (n--){
			int t; scanf ("%d",&t); chk.insert(t);
		}

		vector<pair<int, int> > u;
		for (auto &p : dist[x]){
			u.push_back({p.second,p.first});
		}
		sort(u.begin(),u.end());
		for (auto &p : u){
			if(!chk.count(p.second)){
				printf ("%d %d\n",p.second,p.first);
				break;
			}
		}
	}

	return 0;
}

Compilation message

mart.cpp: In function 'std::pair<int, int> mx(std::map<int, int>&)':
mart.cpp:22:7: warning: 'auto' changes meaning in C++11; please remove it [-Wc++0x-compat]
  for (auto &p : m){
       ^
mart.cpp:22:13: error: ISO C++ forbids declaration of 'p' with no type [-fpermissive]
  for (auto &p : m){
             ^
mart.cpp:22:17: warning: range-based 'for' loops only available with -std=c++11 or -std=gnu++11
  for (auto &p : m){
                 ^
mart.cpp:23:17: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
   ret = max(ret,{p.second,p.first});
                 ^
mart.cpp:23:20: error: request for member 'second' in 'p', which is of non-class type 'int'
   ret = max(ret,{p.second,p.first});
                    ^
mart.cpp:23:29: error: request for member 'first' in 'p', which is of non-class type 'int'
   ret = max(ret,{p.second,p.first});
                             ^
mart.cpp:23:35: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
   ret = max(ret,{p.second,p.first});
                                   ^
mart.cpp:23:35: error: no matching function for call to 'max(std::pair<int, int>&, <brace-enclosed initializer list>)'
In file included from /usr/include/c++/5/algorithm:61:0,
                 from mart.cpp:2:
/usr/include/c++/5/bits/stl_algobase.h:219:5: note: candidate: const _Tp& std::max(const _Tp&, const _Tp&) [with _Tp = std::pair<int, int>]
     max(const _Tp& __a, const _Tp& __b)
     ^
/usr/include/c++/5/bits/stl_algobase.h:219:5: note:   no known conversion for argument 2 from '<brace-enclosed initializer list>' to 'const std::pair<int, int>&'
/usr/include/c++/5/bits/stl_algobase.h:265:5: note: candidate: template<class _Tp, class _Compare> const _Tp& std::max(const _Tp&, const _Tp&, _Compare)
     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
     ^
/usr/include/c++/5/bits/stl_algobase.h:265:5: note:   template argument deduction/substitution failed:
mart.cpp:23:35: note:   candidate expects 3 arguments, 2 provided
   ret = max(ret,{p.second,p.first});
                                   ^
mart.cpp: In function 'int main()':
mart.cpp:34:10: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
   Q.push({x,x,0});
          ^
mart.cpp:34:17: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
   Q.push({x,x,0});
                 ^
mart.cpp:40:18: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
   G[x].push_back({y,c});
                  ^
mart.cpp:40:23: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
   G[x].push_back({y,c});
                       ^
mart.cpp:41:18: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
   G[y].push_back({x,c});
                  ^
mart.cpp:41:23: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
   G[y].push_back({x,c});
                       ^
mart.cpp:47:8: warning: 'auto' changes meaning in C++11; please remove it [-Wc++0x-compat]
   for (auto &p : G[x]){
        ^
mart.cpp:47:14: error: ISO C++ forbids declaration of 'p' with no type [-fpermissive]
   for (auto &p : G[x]){
              ^
mart.cpp:47:18: warning: range-based 'for' loops only available with -std=c++11 or -std=gnu++11
   for (auto &p : G[x]){
                  ^
mart.cpp:48:14: error: request for member 'first' in 'p', which is of non-class type 'int'
    int y = p.first;
              ^
mart.cpp:49:19: error: request for member 'second' in 'p', which is of non-class type 'int'
    int nc = c + p.second;
                   ^
mart.cpp:54:6: warning: 'auto' changes meaning in C++11; please remove it [-Wc++0x-compat]
      auto p = mx(dist[y]);
      ^
mart.cpp:54:11: error: 'p' does not name a type
      auto p = mx(dist[y]);
           ^
mart.cpp:55:22: error: request for member 'second' in 'p', which is of non-class type 'int'
      dist[y].erase(p.second);
                      ^
mart.cpp:57:12: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
     Q.push({s,y,nc});
            ^
mart.cpp:57:20: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
     Q.push({s,y,nc});
                    ^
mart.cpp:70:8: warning: 'auto' changes meaning in C++11; please remove it [-Wc++0x-compat]
   for (auto &p : dist[x]){
        ^
mart.cpp:70:14: error: ISO C++ forbids declaration of 'p' with no type [-fpermissive]
   for (auto &p : dist[x]){
              ^
mart.cpp:70:18: warning: range-based 'for' loops only available with -std=c++11 or -std=gnu++11
   for (auto &p : dist[x]){
                  ^
mart.cpp:71:16: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
    u.push_back({p.second,p.first});
                ^
mart.cpp:71:19: error: request for member 'second' in 'p', which is of non-class type 'int'
    u.push_back({p.second,p.first});
                   ^
mart.cpp:71:28: error: request for member 'first' in 'p', which is of non-class type 'int'
    u.push_back({p.second,p.first});
                            ^
mart.cpp:71:34: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
    u.push_back({p.second,p.first});
                                  ^
mart.cpp:71:34: error: no matching function for call to 'std::vector<std::pair<int, int> >::push_back(<brace-enclosed initializer list>)'
In file included from /usr/include/c++/5/vector:64:0,
                 from mart.cpp:3:
/usr/include/c++/5/bits/stl_vector.h:913:7: note: candidate: void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; std::vector<_Tp, _Alloc>::value_type = std::pair<int, int>]
       push_back(const value_type& __x)
       ^
/usr/include/c++/5/bits/stl_vector.h:913:7: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const value_type& {aka const std::pair<int, int>&}'
mart.cpp:74:8: warning: 'auto' changes meaning in C++11; please remove it [-Wc++0x-compat]
   for (auto &p : u){
        ^
mart.cpp:74:14: error: ISO C++ forbids declaration of 'p' with no type [-fpermissive]
   for (auto &p : u){
              ^
mart.cpp:74:18: warning: range-based 'for' loops only available with -std=c++11 or -std=gnu++11
   for (auto &p : u){
                  ^
mart.cpp:75:20: error: request for member 'second' in 'p', which is of non-class type 'int'
    if(!chk.count(p.second)){
                    ^
mart.cpp:76:25: error: request for member 'second' in 'p', which is of non-class type 'int'
     printf ("%d %d\n",p.second,p.first);
                         ^
mart.cpp:76:34: error: request for member 'first' in 'p', which is of non-class type 'int'
     printf ("%d %d\n",p.second,p.first);
                                  ^
mart.cpp:30:35: 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:32:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int x; scanf ("%d",&x);
                         ^
mart.cpp:39:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf ("%d %d %d",&x,&y,&c);
                              ^
mart.cpp:65:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf ("%d %d",&x,&n); while (n--){
                        ^
mart.cpp:66:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    int t; scanf ("%d",&t); chk.insert(t);
                          ^