This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<int> a(m), b(m), c(m);
for (int i = 0; i < m; i++) {
cin >> a[i] >> b[i] >> c[i];
--a[i]; --b[i];
}
int res = n;
for (int mask = 0; mask < (1 << m); mask++) {
vector<int> cnt(n);
for (int i = 0; i < m; i++) {
if (mask >> i & 1) {
swap(a[i], b[i]);
}
int p = a[i];
while (p != b[i]) {
cnt[p] += 1;
p = (p + 1) % n;
}
if (mask >> i & 1) {
swap(a[i], b[i]);
}
}
res = min(res, *max_element(cnt.begin(), cnt.end()));
}
cout << res << '\n';
return 0;
}
# | 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... |