Submission #900407

# Submission time Handle Problem Language Result Execution time Memory
900407 2024-01-08T08:57:47 Z nguyentunglam Stations (IOI20_stations) C++17
100 / 100
600 ms 10052 KB
#include "stations.h"
#include <vector>

#include<bits/stdc++.h>
using namespace std;

const int N = 1e5 + 10;

int st[N], ed[N], t[N], f[N], order[N], timer;

vector<int> adj[N];

void dfs(int u, int p) {
  st[u] = ++timer;
  for(int &v : adj[u]) if (v != p) {
    t[v] = t[u] ^ 1;
    dfs(v, u);
  }
  ed[u] = timer;
  if (!t[u]) f[u] = st[u];
  else f[u] = ed[u];
}

std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
  for(int i = 0; i < n; i++) adj[i].clear(), st[i] = ed[i] = 0;

  for(int i = 0; i < u.size(); i++) {
    adj[u[i]].push_back(v[i]);
    adj[v[i]].push_back(u[i]);
  }

  timer = -1;
  dfs(0, -1);

//	if (st[0]) assert(0);
  for(int i = 0; i < n; i++) order[i] = i;

  sort(order, order + n, [] (const int &x, const int &y) {
    if (f[x] != f[y]) return f[x] < f[y];
    if (t[x] && t[y]) return st[x] > st[y];
    return t[x] < t[y];
       });

	vector<int> labels(n);

	timer = 0;

  for(int cur = 0; cur < n; cur++) {
    int i = order[cur];
    labels[i] = timer++;
  }


//  cout << st[3] << endl;

//	cout << "labels :"; for(int i = 0; i < n; i++) cout << labels[i] << " "; cout << endl;
////	cout << ed[1] << endl;
//	for(int i = 0; i < n; i++) cout << st[i] << " "; cout << endl;
//	for(int i = 0; i < n; i++) cout << ed[i] << " "; cout << endl;
////	cout << st[0] << endl;
//	cout << endl;
	return labels;
}

int find_next_station(int s, int t, std::vector<int> c) {
//  for(int &j : c) cout << j << " "; cout << endl;
  if (c.size() == 1) return c.back();
  if (!s) {
    for(int &v : c) if (v >= t) return v;
    assert(0);
  }
  if (s <= c[0]) { // st - ed
//    cout << 11 << endl;
    if (s <= t && t <= c.back()) {
      int ret = 1e9;
      for(int &v : c) if (v >= t) ret = min(ret, v);
      return ret;
    }
    return c.back();
  }
  else { // ed - st
//    cout << 22 << endl;
//    cout << c[1] << " " << s << " " << t << endl;
    if (c[1] <= t && t <= s) {
      int ret = 0;
      for(int &v : c) if (v <= t) ret = max(ret, v);
//      cout << ret << endl;
      return ret;
    }
    return c[0];
  }
}

Compilation message

stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:27:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |   for(int i = 0; i < u.size(); i++) {
      |                  ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 358 ms 9528 KB Output is correct
2 Correct 278 ms 9520 KB Output is correct
3 Correct 564 ms 9388 KB Output is correct
4 Correct 423 ms 9388 KB Output is correct
5 Correct 411 ms 9388 KB Output is correct
6 Correct 323 ms 9520 KB Output is correct
7 Correct 264 ms 9388 KB Output is correct
8 Correct 2 ms 9476 KB Output is correct
9 Correct 3 ms 9476 KB Output is correct
10 Correct 2 ms 9472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 251 ms 9476 KB Output is correct
2 Correct 315 ms 9428 KB Output is correct
3 Correct 530 ms 9388 KB Output is correct
4 Correct 380 ms 9388 KB Output is correct
5 Correct 326 ms 9388 KB Output is correct
6 Correct 256 ms 9388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 300 ms 9532 KB Output is correct
2 Correct 263 ms 9644 KB Output is correct
3 Correct 513 ms 9388 KB Output is correct
4 Correct 393 ms 9388 KB Output is correct
5 Correct 329 ms 9388 KB Output is correct
6 Correct 265 ms 9672 KB Output is correct
7 Correct 269 ms 9388 KB Output is correct
8 Correct 2 ms 9476 KB Output is correct
9 Correct 4 ms 9476 KB Output is correct
10 Correct 2 ms 9476 KB Output is correct
11 Correct 373 ms 9388 KB Output is correct
12 Correct 311 ms 9492 KB Output is correct
13 Correct 310 ms 9536 KB Output is correct
14 Correct 297 ms 9388 KB Output is correct
15 Correct 28 ms 9636 KB Output is correct
16 Correct 35 ms 9544 KB Output is correct
17 Correct 57 ms 9560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 600 ms 9388 KB Output is correct
2 Correct 443 ms 9388 KB Output is correct
3 Correct 376 ms 9388 KB Output is correct
4 Correct 2 ms 9476 KB Output is correct
5 Correct 4 ms 9476 KB Output is correct
6 Correct 2 ms 9480 KB Output is correct
7 Correct 395 ms 9388 KB Output is correct
8 Correct 563 ms 9600 KB Output is correct
9 Correct 486 ms 9388 KB Output is correct
10 Correct 353 ms 9388 KB Output is correct
11 Correct 4 ms 9476 KB Output is correct
12 Correct 4 ms 9472 KB Output is correct
13 Correct 4 ms 9476 KB Output is correct
14 Correct 3 ms 9476 KB Output is correct
15 Correct 2 ms 9476 KB Output is correct
16 Correct 294 ms 9388 KB Output is correct
17 Correct 317 ms 9388 KB Output is correct
18 Correct 337 ms 9388 KB Output is correct
19 Correct 334 ms 9388 KB Output is correct
20 Correct 282 ms 9388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 318 ms 9776 KB Output is correct
2 Correct 264 ms 9528 KB Output is correct
3 Correct 566 ms 9388 KB Output is correct
4 Correct 441 ms 9388 KB Output is correct
5 Correct 397 ms 9388 KB Output is correct
6 Correct 256 ms 9536 KB Output is correct
7 Correct 268 ms 9388 KB Output is correct
8 Correct 3 ms 9476 KB Output is correct
9 Correct 4 ms 9476 KB Output is correct
10 Correct 2 ms 9476 KB Output is correct
11 Correct 301 ms 9724 KB Output is correct
12 Correct 338 ms 9452 KB Output is correct
13 Correct 584 ms 9388 KB Output is correct
14 Correct 466 ms 9388 KB Output is correct
15 Correct 375 ms 9388 KB Output is correct
16 Correct 294 ms 9392 KB Output is correct
17 Correct 331 ms 9388 KB Output is correct
18 Correct 267 ms 9756 KB Output is correct
19 Correct 276 ms 9800 KB Output is correct
20 Correct 242 ms 9388 KB Output is correct
21 Correct 30 ms 9440 KB Output is correct
22 Correct 41 ms 9704 KB Output is correct
23 Correct 63 ms 9472 KB Output is correct
24 Correct 4 ms 9476 KB Output is correct
25 Correct 4 ms 9492 KB Output is correct
26 Correct 4 ms 9476 KB Output is correct
27 Correct 3 ms 9472 KB Output is correct
28 Correct 2 ms 9476 KB Output is correct
29 Correct 290 ms 9388 KB Output is correct
30 Correct 291 ms 9388 KB Output is correct
31 Correct 286 ms 9388 KB Output is correct
32 Correct 277 ms 9388 KB Output is correct
33 Correct 281 ms 9388 KB Output is correct
34 Correct 194 ms 9508 KB Output is correct
35 Correct 226 ms 10052 KB Output is correct
36 Correct 267 ms 9776 KB Output is correct
37 Correct 261 ms 9540 KB Output is correct
38 Correct 242 ms 9776 KB Output is correct
39 Correct 265 ms 9956 KB Output is correct
40 Correct 257 ms 9764 KB Output is correct
41 Correct 262 ms 9756 KB Output is correct
42 Correct 36 ms 9548 KB Output is correct
43 Correct 54 ms 9720 KB Output is correct
44 Correct 73 ms 9564 KB Output is correct
45 Correct 94 ms 9500 KB Output is correct
46 Correct 177 ms 9464 KB Output is correct
47 Correct 160 ms 9488 KB Output is correct
48 Correct 34 ms 9844 KB Output is correct
49 Correct 34 ms 10044 KB Output is correct