CSES - HIIT Open 2017 - Results
Submission details
Task:Factory
Sender:Ace of Spades
Submission time:2017-05-27 15:58:18 +0300
Language:C++
Status:READY
Result:
Test results
testverdicttime
#10.05 sdetails
#20.04 sdetails
#30.04 sdetails
#40.06 sdetails
#50.14 sdetails
#60.10 sdetails
#70.11 sdetails
#80.08 sdetails
#90.09 sdetails
#100.10 sdetails
#110.12 sdetails
#120.10 sdetails
#130.12 sdetails
#140.11 sdetails
#150.10 sdetails
#160.03 sdetails
#170.04 sdetails

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:21:32: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < jo.size(); ++i) {
                                ^
input/code.cpp:23:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int j = 0; j < v[x].size(); ++j) {
                               ^

Code

#include <bits/stdc++.h>
using namespace std;
const int MN = 555;
int in_cnt[MN];
vector<int> v[MN];
int main() {
    int n,m;
    cin>>n>>m;
    for(int i = 0; i < m; ++i) {
	int a,b;
	cin>>a>>b;
	v[a].push_back(b);
	++in_cnt[b];
    }
    vector<int> jo;
    for(int i = 1; i <= n; ++i) {
	if(in_cnt[i] == 0) {
	    jo.push_back(i);
	}
    }
    for(int i = 0; i < jo.size(); ++i) {
	int x = jo[i];
	for(int j = 0; j < v[x].size(); ++j) {
	    int y = v[x][j];
	    --in_cnt[y];
	    if(in_cnt[y] == 0) {
		jo.push_back(y);
	    }
	}
    }
    for(int i = 1; i <= n; ++i) {
	if(in_cnt[i]) {
	    cout<<"LUL\n";
	    while(1);
	}
    }
    for(int i = 1; i <= n; ++i) {
	for(auto x: v[i]) {
	    ++in_cnt[x];
	}
    }
    int ans = 0;
    int jonne[MN] = {0};
    bool visited[MN] = {0};
    for(int i = (int)jo.size()-1; i >= 0; --i) {
	int x = jo[i];
	for(auto y: v[x]) {
	    jonne[x] += jonne[y];
	}
	jonne[x]++;
    }
    /*
    cout<<'\n'<<'\n';
    for(int i = 1; i <= n; ++i) {
	cout<<i<<' '<<jonne[i]<<'\n';
    }
    cout<<'\n';
    */
    int ans2 = 1e9;
    for(int i = 0; i < 500; ++i) {
	ans = 0;
	while(1) {
	    vector<pair<int, int> > v2;
	    for(int i = 1; i <= n; ++i) {
		if(!visited[i] && in_cnt[i] == 0) {
		    v2.push_back({jonne[i], i});
		}
	    }
	    if(v2.size() == 0) {
		break;
	    }
	    ++ans;
	    sort(v2.begin(), v2.end());
	    for(int i = 0; i < 2; ++i) {
		if(v2.size()) {
		    int x = v2.back().second;
		    v2.pop_back();
		    visited[x] = 1;
		    for(auto y: v[x]) {
			--in_cnt[y];
		    }
		}
	    }
	}
	ans2 = min(ans, ans2);
    }
    cout<<ans2<<endl;
}

Test details

Test 1

Verdict:

input
1 0

correct output
1

user output
0

Test 2

Verdict:

input
2 0

correct output
1

user output
0

Test 3

Verdict:

input
2 1
2 1

correct output
2

user output
0

Test 4

Verdict:

input
500 0

correct output
250

user output
0

Test 5

Verdict:

input
500 124750
66 104
50 159
173 457
200 154
...

correct output
500

user output
0

Test 6

Verdict:

input
500 96771
376 390
243 497
417 360
107 80
...

correct output
413

user output
0

Test 7

Verdict:

input
500 106799
96 245
68 62
122 119
460 454
...

correct output
433

user output
0

Test 8

Verdict:

input
500 83550
76 338
111 174
88 142
114 463
...

correct output
365

user output
0

Test 9

Verdict:

input
500 98051
281 60
312 284
270 474
385 224
...

correct output
410

user output
0

Test 10

Verdict:

input
500 86622
5 320
50 107
182 483
385 500
...

correct output
372

user output
0

Test 11

Verdict:

input
500 99445
421 286
392 406
155 290
475 453
...

correct output
396

user output
0

Test 12

Verdict:

input
500 99832
283 149
315 396
264 422
224 388
...

correct output
410

user output
0

Test 13

Verdict:

input
500 116149
446 185
232 35
498 391
189 63
...

correct output
457

user output
0

Test 14

Verdict:

input
500 84757
71 205
286 360
184 486
30 228
...

correct output
364

user output
0

Test 15

Verdict:

input
500 108617
126 250
76 224
449 69
200 63
...

correct output
439

user output
0

Test 16

Verdict:

input
10 20
7 8
1 3
4 8
5 9
...

correct output
5

user output
0

Test 17

Verdict:

input
10 20
2 9
9 8
4 3
7 3
...

correct output
5

user output
0