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;
#define ll long long
int main(){
ios_base::sync_with_stdio(false);
#ifdef LOCAL_DEFINE
freopen("input.txt", "r", stdin);
#endif
int n, e;
cin >> n >> e;
vector<tuple<int,int,int>> adj(e+1);
for(int i = 0; i < e; i++){
int a,b;
cin>>a>>b;
adj[i] = make_tuple(a,b,i+1);
}
vector<int> v(n);
for(int i = 0; i < n-1; i++){
cin >> v[i];
}
sort(v.begin(), v.end());
int best = INT_MAX;
vector<int> ans(n+3, 0);
for(int i = 0; i < n-1; i++){
int a,b,c,sum=0;
tie(a,b,c) = adj[v[i]-1];
int oldv = c, newv = 1;
int diff = oldv - newv;
//cerr << diff << ' ' << oldv << ' ' << newv << ' ' << i << ' ' << v[i] << '\n';
//cerr << a << ' ' << b << ' ' << c << ' ' << v[i] << '\n';
sum += 1;
for(int j = 0; j < n-1; j++){
if(i==j) continue;
int a1,b1,c1;
tie(a1,b1,c1) = adj[v[j]-1];
sum += ((c1-diff+e)%e);
}
if(sum<best){
for(int i = 1; i <= e; i++){
ans[i] = ((i-diff+e)%e);
}
}
}
for(int i = 1; i <= e; i++) cout << (ans[i]==0?e:ans[i]) << ' ';
cout << '\n';
}
# | 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... |