Please, try EDU on Codeforces! New educational section with videos, subtitles, texts, and problems. ×

### zhatabsaifi's blog

By zhatabsaifi, history, 5 weeks ago, , I saw the code of one of the Div1 candidate.But in the last codeforces contest [contest:Codeforces Round #647 (Div. 2) — Thanks, Algo Muse!] and question is [problem:Johnny and Contribution].
This code is successfully submitted by codeforces but it failed on this test case.
4 3
1 2
2 3
3 4
1 3 3 1

This code give 1 4 2 3 answer and the actual answer is -1.
82508768

~~~~~

#include <fstream>
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>
#include <queue>

using namespace std;

const int Nmax = 500005;
const int INF = 1000000000;
const int MOD = 998244353;

pair<int, int> a[Nmax];
vector<int> L[Nmax];
bool fr[Nmax];
int color[Nmax];

int main()
{
int t, n, m;
#ifndef ONLINE_JUDGE
freopen ("data.in","r",stdin);
freopen ("data.out","w",stdout);
#endif
cin.sync_with_stdio( false );
cin >> n >> m;
while(m--) {
int x, y;
cin >> x >> y;
L[x].push_back(y);
L[y].push_back(x);
}
for(int i = 1; i <= n; i++) {
int x;
cin >> x;
color[i] = x;
a[i] = {x, i};
}
sort(a + 1, a + n + 1);
for(int i = 1; i <= n; i++) {
int node = a[i].second;
int nr_dif = 0;
for(auto it : L[node]) {
if(color[it] <= color[node]) {
nr_dif += (fr[color[it]] == false);
fr[color[it]] = true;
}
}
if(nr_dif != color[node] &mdash; 1) {
cout << "-1\n";
return 0;
}
for(auto it : L[node]) {
fr[color[it]] = false;
}
}
for(int i = 1; i <= n; i++) {
cout << a[i].second << " ";
}
return 0;
}


~~~~~

So, how does codeforces check the code of div1 users ? Comments (5)
 » Auto comment: topic has been updated by zhatabsaifi (previous revision, new revision, compare).
 » I don't understand what are you saying. You can see that the code was hacked.
•  » » yes but codeforces is accepted this code.
 » Hey, man!I don't have insights about the exact process, but as most platforms/contests do, the problemsetters come up for each problem with the statements and the test cases. My code was judged on the test cases the problemsetters have provided, which did not include the special case that I haven't taken into account. It was just a matter of luck for me that the solution is Accepted. As you can see, someone uphacked it after the contest.
 » 5 weeks ago, # | ← Rev. 3 →