이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int tp[2000001];
bitset<2000005> vb;
int main() {
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
int n, m;
cin >> n >> m;
vector<int> vi;
for (int i = 0; i < n; i++) {
int a, b;
cin >> a >> b;
vi.push_back(a), vi.push_back(b);
tp[a] = b, tp[b] = a;
}
vi.push_back(0);
sort(vi.begin(), vi.end());
// for (auto a : vpii) cout << a.first << " " << a.second << "\n";
vector<int> cyc;
int special;
for (int i = 0; i < vi.size(); i++)
if (!vb[i]) {
// cout << "I = " << i << '\n';
int cy = 0;
function<void(int)> dfs;
dfs = [&](int cur) {
if(cur==vi.size())
{
special = cy - 1;
return;
}
// cout << cur << "\n";
if (vb[cur]) {
cyc.push_back(cy);
return;
}
vb[cur] = 1;
cy++;
dfs(lower_bound(vi.begin(), vi.end(),
tp[vi[cur]]) -
vi.begin() + 1);
};
dfs(i);
}
// for (auto a : cyc) cout << a << ' ';
// cout << "\n";
sort(cyc.begin(), cyc.end(), greater<int>());
if (m >= cyc.size()) {
int x = (m - cyc.size());
int val = x / 2 * 4 + x % 2;
cout << special + accumulate(cyc.begin(), cyc.end(), 0) + cyc.size() * 2 +
val
<< "\n";
} else
cout << special + accumulate(cyc.begin(), cyc.begin() + m, 0) + 2 * m
<< "\n";
}
컴파일 시 표준 에러 (stderr) 메시지
teleporters.cpp: In function 'int main()':
teleporters.cpp:22:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
22 | for (int i = 0; i < vi.size(); i++)
| ~~^~~~~~~~~~~
teleporters.cpp: In lambda function:
teleporters.cpp:28:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
28 | if(cur==vi.size())
| ~~~^~~~~~~~~~~
teleporters.cpp: In function 'int main()':
teleporters.cpp:49:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
49 | if (m >= cyc.size()) {
| ~~^~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |