답안 #110464

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
110464 2019-05-10T21:21:51 Z ioilolcom 꿈 (IOI13_dreaming) C++14
컴파일 오류
0 ms 0 KB
#include "dreaming.h"
#include <bits/stdc++.h>
#define y second
#define x  first
#define ll long long int
#define pb push_back
#define pii pair<int,int>
using namespace std;
const int N=1e5+7;
vector<pair<int,int> > adj[N];
bool vis[N];
void dfs(int node,int p,int length,pii &ans){
	vis[node]=1;
	for(auto vertice:adj[node]) {
		if(vertice.x==p) {
			continue;
		}
		dfs(vertice.x,node,length+vertice.y,ans);
	}
	if(length>ans.y) {
		ans.x=node;
		ans.y=length;
	}
}
bool fn(int s,int e,int p,vector<int> &path){
	if(s==e) {
		return true;
	}
	for(auto v:adj[s]) {
		if(v.x==p) continue;
		if(fn(v.x,e,s,path)) {
			path.push_back(v.x);
			return true;
		}
	}
	return false;
}
map<pair<int,int> >cost;
int travelTime(int n, int m, int l, int A[], int B[], int T[]) {
	N = n;
	M = m;
	L = l;
	for(int i = 0; i < M; i++) {
		adj[A[i]].push_back(make_pair(B[i], T[i]));
		adj[B[i]].push_back(make_pair(A[i], T[i]));
		cost[make_pair(A[i], B[i])] = cost[make_pair(B[i], A[i])] = T[i];
	}
	int ans = 0;
	vector <int> a;
	for(int i = 0; i < N; i++) {
		if(vis[i]) continue;
		pair <int, int> f = make_pair(-1, -1);
		dfs(i, -1, 0, f);
		pair <int, int> s = make_pair(-1, -1);
		dfs(f.first, -1, 0, s);
		ans = max(ans, s.second);
		//path.clear();
		vector<int> path;
		fn(f.first,  s.first,-1,path);
		path.push_back(f.first);
		int c = s.second;
		int cur = s.second;
		for(int j = 1; j < path.size(); j++) {
			cur -= cost[make_pair(path[j], path[j - 1])];
			c = min(c, max(cur, s.second - cur));
		}
		a.push_back(c);
	}
	sort(a.rbegin(), a.rend());
	if(a.size() > 1)
		ans = max(ans, a[0] + a[1] + L);
	if(a.size() > 2)
		ans = max(ans, a[1] + a[2] + 2 * L);
	return ans;
}

Compilation message

dreaming.cpp:38:19: error: wrong number of template arguments (1, should be at least 2)
 map<pair<int,int> >cost;
                   ^
In file included from /usr/include/c++/7/map:61:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:81,
                 from dreaming.cpp:2:
/usr/include/c++/7/bits/stl_map.h:99:11: note: provided for 'template<class _Key, class _Tp, class _Compare, class _Alloc> class std::map'
     class map
           ^~~
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:40:6: error: assignment of read-only variable 'N'
  N = n;
      ^
dreaming.cpp:41:2: error: 'M' was not declared in this scope
  M = m;
  ^
dreaming.cpp:42:2: error: 'L' was not declared in this scope
  L = l;
  ^
dreaming.cpp:46:7: error: no match for 'operator[]' (operand types are 'int' and 'std::pair<int, int>')
   cost[make_pair(A[i], B[i])] = cost[make_pair(B[i], A[i])] = T[i];
       ^
dreaming.cpp:46:37: error: no match for 'operator[]' (operand types are 'int' and 'std::pair<int, int>')
   cost[make_pair(A[i], B[i])] = cost[make_pair(B[i], A[i])] = T[i];
                                     ^
dreaming.cpp:63:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j = 1; j < path.size(); j++) {
                  ~~^~~~~~~~~~~~~
dreaming.cpp:64:15: error: no match for 'operator[]' (operand types are 'int' and 'std::pair<int, int>')
    cur -= cost[make_pair(path[j], path[j - 1])];
               ^