제출 #559382

#제출 시각아이디문제언어결과실행 시간메모리
559382OlympiaTug of War (BOI15_tug)C++17
0 / 100
55 ms3924 KiB
#include <bits/stdc++.h> using namespace std; vector<vector<pair<int,int> > > adj; vector<bool> hasVisited; int ans = 0; void dfs (int curNode, int prevNode) { if (hasVisited[curNode]) { return; } hasVisited[curNode] = true; for (pair<int,int> p: adj[curNode]) { if (p.first != prevNode) { ans += p.second; dfs (p.first, curNode); } } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, k; cin >> n >> k; adj.resize(2 * n); hasVisited.assign(2 * n, false); map<pair<int,int>,vector<int> > myMap; for (int i = 0; i < 2 * n; i++) { int u, v, w; cin >> u >> v >> w; u--, v--; v += n; myMap[make_pair(u, v)].push_back(w); adj[u].push_back(make_pair(v, w)); adj[v].push_back(make_pair(u, -w)); } vector<int> tot; for (int i = 0; i < n; i++) { if (!hasVisited[i]) { ans = 0; if (adj[i].empty()) { cout << "NO\n"; exit(0); } dfs (i, adj[i].back().first); tot.push_back(abs(ans)); } } for (auto& p: myMap) { if (p.second.size() <= 1) { continue; } int a = 0; for (int j = 0; j < p.second.size(); j++) { if (j % 2) a += p.second[j]; else a -= p.second[j]; } tot.push_back(abs(a)); } bitset<60000> bs; bs.set(30000); for (int j: tot) { bs = (bs >> j) | (bs << j); } for (int i = 0; i <= k; i++) { if (bs[30000 + i]) { cout << "YES\n"; return 0; } } cout << "NO\n"; }

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

tug.cpp: In function 'int main()':
tug.cpp:53:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |         for (int j = 0; j < p.second.size(); j++) {
      |                         ~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...