제출 #97215

#제출 시각아이디문제언어결과실행 시간메모리
97215E869120여행하는 상인 (APIO17_merchant)C++14
100 / 100
806 ms2552 KiB
#include <iostream> #include <algorithm> #include <vector> using namespace std; long long N, M, K, B[109][1009], S[109][1009]; long long dist[109][109], V[109][109], D[109][109], col[109]; long double dp[109], e[109][109]; vector<int>G[109], I; void dfs(int pos) { if (col[pos] == 1) return; col[pos] = 1; for (int i = 0; i < G[pos].size(); i++) dfs(G[pos][i]); } bool solve(long double c) { for (int i = 1; i <= N; i++) { for (int j = 1; j <= N; j++) { if (dist[i][j] == (1LL << 60) || V[i][j] == -(1LL << 60)) { e[i][j] = 1e18; continue; } e[i][j] = 1.0L * c * dist[i][j] - 1.0L * V[i][j]; } } for (int i = 1; i <= N; i++) dp[i] = (1LL << 60); for (int i = 0; i < I.size(); i++) dp[I[i]] = 0; for (int i = 1; i <= 2 * N; i++) { for (int j = 1; j <= N; j++) { for (int k = 1; k <= N; k++) { dp[k] = min(dp[k], dp[j] + e[j][k]); } } } vector<long double>E1; for (int i = 1; i <= N; i++) E1.push_back(dp[i]); for (int i = 1; i <= N; i++) { for (int j = 1; j <= N; j++) { for (int k = 1; k <= N; k++) { dp[k] = min(dp[k], dp[j] + e[j][k]); } } } vector<long double>E2; for (int i = 1; i <= N; i++) E2.push_back(dp[i]); if (E1 == E2) return false; return true; } int main() { cin >> N >> M >> K; for (int i = 1; i <= N; i++) { for (int j = 1; j <= N; j++) { dist[i][j] = (1LL << 60); D[i][i] = 1; } } for (int i = 1; i <= N; i++) { for (int j = 1; j <= K; j++) cin >> B[i][j] >> S[i][j]; } for (int i = 1; i <= M; i++) { long long a1, a2, a3; cin >> a1 >> a2 >> a3; dist[a1][a2] = a3; } for (int k = 1; k <= N; k++) { for (int i = 1; i <= N; i++) { for (int j = 1; j <= N; j++) dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]); } } for (int i = 1; i <= N; i++) { for (int j = 1; j <= N; j++) { long long Benq = 0; for (int k = 1; k <= K; k++) { if (S[j][k] == -1 || B[i][k] == -1) continue; Benq = max(Benq, S[j][k] - B[i][k]); } if (dist[i][j] != (1LL << 60)) { V[i][j] = Benq; D[i][j] = 1; } else V[i][j] = -(1LL << 60); } } for (int k = 1; k <= N; k++) { for (int i = 1; i <= N; i++) { for (int j = 1; j <= N; j++) { if (D[i][k] == 1 && D[k][j] == 1) D[i][j] = 1; } } } for (int i = 1; i <= N; i++) { for (int j = 1; j <= N; j++) { if (D[i][j] == 1 && D[j][i] == 1) G[i].push_back(j); } } for (int i = 1; i <= N; i++) { if (col[i] == 1) continue; I.push_back(i); dfs(i); } long long L = 1, R = (1LL << 30), MM, maxn = 0; for (int i = 0; i < 35; i++) { MM = (L + R) / 2; bool t = solve(1.0L * MM - 1e-10); if (t == true) { L = MM; maxn = max(maxn, MM); } else { R = MM; } } cout << maxn << endl; return 0; }

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

merchant.cpp: In function 'void dfs(int)':
merchant.cpp:13:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < G[pos].size(); i++) dfs(G[pos][i]);
                  ~~^~~~~~~~~~~~~~~
merchant.cpp: In function 'bool solve(long double)':
merchant.cpp:24:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < I.size(); i++) dp[I[i]] = 0;
                  ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...