# HIIT Open 2017

 Start: 2017-05-27 11:00:00 End: 2017-05-27 16:00:00

CSES - HIIT Open 2017 - Results
History
2017-05-27 15:39:50

## Code

```#include <bits/stdc++.h>

using namespace std;

vector<int> v[501];
vector<int> rv[501];
int vc[501];
int vd[501];
int vs[501];

int main() {
int n, m;
cin >> n >> m;
for(int i=0;i<m;i++) {
int a, b;
cin >> a >> b;
a--; b--;
v[b].push_back(a);
rv[a].push_back(b);
}
queue<int> q;
for(int i=0;i<n;i++) {
if(v[i].size() == 0)
q.push(i);
vc[i] = v[i].size();
}
vector<int> sorted(n);
int j=n-1;
while(q.size() > 0) {
int i = q.front();
q.pop();
sorted[j--]=i;
for(auto& it : rv[i]){
if(!--vc[it])q.push(it);
}
}
priority_queue<tuple<int,int,int>> pq;
for(auto& i : sorted){
vd[i]=1;
vs[i]=1;
for(auto& it : rv[i]){
vs[i]+=vs[it];
if(vd[i]<vd[it]+1)vd[i]=vd[it]+1;
}
vc[i]=v[i].size();
if(vc[i]==0)pq.emplace(vd[i],vs[i],i);
}
int r=0;
int mr=0;
while(pq.size() > 0){
int p,v,i;
tie(p,v,i) = pq.top();
pq.pop();
if(mr==1)mr=0;
else if(pq.size()>0)mr=1,++r;
else ++r;
for(auto& it : rv[i]){
if(!--vc[it])pq.emplace(vd[it],vs[it],it);
}
}
cout<<r<<'\n';
return 0;
}```

## Test details

### Test 1

Verdict: ACCEPTED

input
`1 0`
view   save

correct output
`1`
view   save

user output
`1`
view   save

### Test 2

Verdict: ACCEPTED

input
`2 0`
view   save

correct output
`1`
view   save

user output
`1`
view   save

### Test 3

Verdict: ACCEPTED

input
```2 1 2 1```
view   save

correct output
`2`
view   save

user output
`2`
view   save

### Test 4

Verdict: ACCEPTED

input
`500 0`
view   save

correct output
`250`
view   save

user output
`250`
view   save

### Test 5

Verdict: ACCEPTED

input
```500 124750 66 104 50 159 173 457 200 154 416 492 232 191 205 323 201 403 476 348 191 266 239 422 103 442 295 79 191 352 124 451 97 463 353 194 153 82 166 386 ...```
view   save

correct output
`500`
view   save

user output
`500`
view   save

### Test 6

input
```500 96771 376 390 243 497 417 360 107 80 200 177 107 17 117 486 348 434 262 43 155 79 160 178 247 365 354 101 232 352 414 16 438 80 482 118 484 76 250 183 ...```
view   save

correct output
`413`
view   save

user output
`402`
view   save

### Test 7

input
```500 106799 96 245 68 62 122 119 460 454 378 409 238 455 262 455 217 35 368 195 318 374 215 496 301 311 255 296 171 95 9 431 284 272 261 258 28 316 489 178 ...```
view   save

correct output
`433`
view   save

user output
`427`
view   save

### Test 8

input
```500 83550 76 338 111 174 88 142 114 463 416 168 299 273 373 231 495 345 104 414 416 161 141 21 139 348 381 300 290 414 477 487 173 155 161 260 245 300 465 453 ...```
view   save

correct output
`365`
view   save

user output
`355`
view   save

### Test 9

input
```500 98051 281 60 312 284 270 474 385 224 218 419 201 242 189 271 493 132 344 102 314 408 52 61 21 192 493 486 26 352 227 114 80 296 121 141 457 288 339 410 ...```
view   save

correct output
`410`
view   save

user output
`406`
view   save

### Test 10

input
```500 86622 5 320 50 107 182 483 385 500 280 389 211 467 423 385 88 310 336 130 44 216 320 489 202 105 217 343 42 398 153 200 351 8 318 61 342 322 113 423 ...```
view   save

correct output
`372`
view   save

user output
`350`
view   save

### Test 11

input
```500 99445 421 286 392 406 155 290 475 453 316 105 276 310 325 275 428 21 40 137 211 236 194 89 85 259 87 481 342 299 458 132 382 207 447 49 496 242 308 204 ...```
view   save

correct output
`396`
view   save

user output
`387`
view   save

### Test 12

input
```500 99832 283 149 315 396 264 422 224 388 372 391 333 58 441 470 203 48 323 385 218 366 17 333 176 115 341 107 73 448 380 340 249 165 274 99 345 446 199 399 ...```
view   save

correct output
`410`
view   save

user output
`401`
view   save

### Test 13

input
```500 116149 446 185 232 35 498 391 189 63 252 474 410 472 132 35 41 475 418 173 343 489 131 39 220 241 333 348 17 333 399 257 70 23 89 488 141 122 171 478 ...```
view   save

correct output
`457`
view   save

user output
`456`
view   save

### Test 14

input
```500 84757 71 205 286 360 184 486 30 228 230 365 334 386 20 65 131 2 144 189 276 109 225 311 23 242 453 458 414 149 75 70 10 445 66 236 41 356 124 27 ...```
view   save

correct output
`364`
view   save

user output
`354`
view   save

### Test 15

input
```500 108617 126 250 76 224 449 69 200 63 405 344 143 474 80 131 480 165 135 266 113 369 13 271 287 100 208 167 113 90 145 440 158 427 341 460 404 101 118 373 ...```
view   save

correct output
`439`
view   save

user output
`436`
view   save

### Test 16

Verdict: ACCEPTED

input
```10 20 7 8 1 3 4 8 5 9 2 8 1 7 4 3 10 5 6 5 9 3 10 3 2 4 6 9 1 5 2 3 7 3 5 4 10 7 1 2 ...```
view   save

correct output
`5`
view   save

user output
`5`
view   save

### Test 17

```10 20 2 9 9 8 4 3 7 3 5 1 5 10 2 1 4 10 2 8 4 7 5 8 4 6 5 9 10 6 5 7 4 9 9 10 5 6 7 10 ...```
`5`
`6`