답안 #405744

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
405744 2021-05-16T21:08:28 Z ly20 기지국 (IOI20_stations) C++17
100 / 100
1067 ms 968 KB
#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1123;
int t, ent[MAXN], sd[MAXN], prof[MAXN];
vector <int> grafo[MAXN];
void dfs(int v, int p) {
    ent[v] = t;
    t++;
    for(int i = 0; i < grafo[v].size(); i++) {
        int viz = grafo[v][i];
        if(viz == p) continue;
        prof[viz] = prof[v] + 1;
        dfs(viz, v);
    }
    sd[v] = t;
    t++;
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
	vector<int> labels;
	for(int i =0 ; i < n; i++) grafo[i].clear();
    for(int i = 0; i < u.size(); i++) {
        grafo[u[i]].push_back(v[i]);
        grafo[v[i]].push_back(u[i]);
    }
    prof[0] = 0;
    t = 0;
    dfs(0, 0);
    set <pair <int, int> > s;
    map <pair <int, int>, int> mp;
	for (int i = 0; i < n; i++) {
		if(prof[i] % 2 == 0) s.insert(make_pair(ent[i], 0));
		else s.insert(make_pair(sd[i], 1));
	}
	int at = 0;
	set <pair <int, int> > :: iterator it;
	for(it = s.begin(); it != s.end(); it++) {
        mp[*it] = at++;
	}
    for(int i  = 0; i < n; i++) {
        pair <int, int> a;
        if(prof[i] % 2 == 0) a = make_pair(ent[i], 0);
        else a = make_pair(sd[i], 1);
        labels.push_back(mp[a]);
    }
	return labels;
}

int find_next_station(int s, int t, vector<int> c) {
	int tp, rs, mn = 1123, mx = 0;
	if(c.size() == 1) return c[0];
	for(int i = 0; i < c.size(); i++) {
        int viz = c[i];
        mn = min(viz, mn);
        mx = max(viz, mx);
        if(viz < s) tp = 1;
        if(viz > s) tp = 0;
	}
	vector <int> temp;
	if(tp == 0) {
        rs = mx;
        temp.push_back(s);
        for(int i = 0; i < c.size(); i++) {
            if(c[i] == mx) {
                mx = -mx;
                continue;
            }
            temp.push_back(c[i]);
        }
        sort(temp.begin(), temp.end());
        for(int i = 1; i < temp.size(); i++) {
            if(t >= temp[i - 1] + 1 && t <= temp[i]) {
                return temp[i];
            }
        }
	}
	else {
        rs = mn;
        temp.push_back(s);
        for(int i = 0; i < c.size(); i++) {
            if(c[i] == mn) {
                mn = -mn;
                continue;
            }
            temp.push_back(c[i]);
        }
        sort(temp.begin(), temp.end());
        for(int i = 0; i < temp.size() - 1; i++) {
            if(t >= temp[i] && t <= temp[i + 1] - 1) {
                return temp[i];
            }
        }
	}
    return rs;
}

Compilation message

stations.cpp: In function 'void dfs(int, int)':
stations.cpp:10:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |     for(int i = 0; i < grafo[v].size(); i++) {
      |                    ~~^~~~~~~~~~~~~~~~~
stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:22:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |     for(int i = 0; i < u.size(); i++) {
      |                    ~~^~~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:52:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |  for(int i = 0; i < c.size(); i++) {
      |                 ~~^~~~~~~~~~
stations.cpp:63:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |         for(int i = 0; i < c.size(); i++) {
      |                        ~~^~~~~~~~~~
stations.cpp:71:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |         for(int i = 1; i < temp.size(); i++) {
      |                        ~~^~~~~~~~~~~~~
stations.cpp:80:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   80 |         for(int i = 0; i < c.size(); i++) {
      |                        ~~^~~~~~~~~~
stations.cpp:88:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   88 |         for(int i = 0; i < temp.size() - 1; i++) {
      |                        ~~^~~~~~~~~~~~~~~~~
stations.cpp:60:2: warning: 'tp' may be used uninitialized in this function [-Wmaybe-uninitialized]
   60 |  if(tp == 0) {
      |  ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 668 ms 628 KB Output is correct
2 Correct 540 ms 656 KB Output is correct
3 Correct 985 ms 580 KB Output is correct
4 Correct 752 ms 516 KB Output is correct
5 Correct 720 ms 504 KB Output is correct
6 Correct 579 ms 648 KB Output is correct
7 Correct 495 ms 656 KB Output is correct
8 Correct 3 ms 596 KB Output is correct
9 Correct 6 ms 596 KB Output is correct
10 Correct 2 ms 476 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 526 ms 656 KB Output is correct
2 Correct 661 ms 808 KB Output is correct
3 Correct 980 ms 528 KB Output is correct
4 Correct 808 ms 512 KB Output is correct
5 Correct 570 ms 400 KB Output is correct
6 Correct 557 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 660 ms 656 KB Output is correct
2 Correct 530 ms 896 KB Output is correct
3 Correct 1067 ms 528 KB Output is correct
4 Correct 742 ms 512 KB Output is correct
5 Correct 678 ms 512 KB Output is correct
6 Correct 536 ms 616 KB Output is correct
7 Correct 584 ms 660 KB Output is correct
8 Correct 3 ms 464 KB Output is correct
9 Correct 6 ms 596 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 557 ms 528 KB Output is correct
12 Correct 620 ms 760 KB Output is correct
13 Correct 499 ms 744 KB Output is correct
14 Correct 578 ms 656 KB Output is correct
15 Correct 90 ms 544 KB Output is correct
16 Correct 67 ms 656 KB Output is correct
17 Correct 135 ms 784 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1029 ms 400 KB Output is correct
2 Correct 872 ms 400 KB Output is correct
3 Correct 799 ms 512 KB Output is correct
4 Correct 3 ms 596 KB Output is correct
5 Correct 5 ms 468 KB Output is correct
6 Correct 2 ms 608 KB Output is correct
7 Correct 782 ms 516 KB Output is correct
8 Correct 982 ms 508 KB Output is correct
9 Correct 816 ms 528 KB Output is correct
10 Correct 647 ms 528 KB Output is correct
11 Correct 7 ms 468 KB Output is correct
12 Correct 6 ms 596 KB Output is correct
13 Correct 4 ms 596 KB Output is correct
14 Correct 5 ms 468 KB Output is correct
15 Correct 2 ms 476 KB Output is correct
16 Correct 620 ms 528 KB Output is correct
17 Correct 632 ms 412 KB Output is correct
18 Correct 541 ms 528 KB Output is correct
19 Correct 599 ms 504 KB Output is correct
20 Correct 681 ms 508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 705 ms 656 KB Output is correct
2 Correct 671 ms 652 KB Output is correct
3 Correct 963 ms 508 KB Output is correct
4 Correct 810 ms 512 KB Output is correct
5 Correct 691 ms 512 KB Output is correct
6 Correct 538 ms 640 KB Output is correct
7 Correct 583 ms 640 KB Output is correct
8 Correct 3 ms 592 KB Output is correct
9 Correct 6 ms 596 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
11 Correct 518 ms 640 KB Output is correct
12 Correct 633 ms 640 KB Output is correct
13 Correct 913 ms 492 KB Output is correct
14 Correct 872 ms 536 KB Output is correct
15 Correct 744 ms 400 KB Output is correct
16 Correct 583 ms 632 KB Output is correct
17 Correct 629 ms 512 KB Output is correct
18 Correct 510 ms 764 KB Output is correct
19 Correct 616 ms 728 KB Output is correct
20 Correct 545 ms 636 KB Output is correct
21 Correct 58 ms 576 KB Output is correct
22 Correct 85 ms 676 KB Output is correct
23 Correct 110 ms 788 KB Output is correct
24 Correct 5 ms 544 KB Output is correct
25 Correct 6 ms 608 KB Output is correct
26 Correct 7 ms 464 KB Output is correct
27 Correct 5 ms 596 KB Output is correct
28 Correct 3 ms 600 KB Output is correct
29 Correct 665 ms 400 KB Output is correct
30 Correct 615 ms 400 KB Output is correct
31 Correct 554 ms 508 KB Output is correct
32 Correct 554 ms 636 KB Output is correct
33 Correct 589 ms 528 KB Output is correct
34 Correct 371 ms 656 KB Output is correct
35 Correct 521 ms 872 KB Output is correct
36 Correct 508 ms 748 KB Output is correct
37 Correct 542 ms 768 KB Output is correct
38 Correct 496 ms 720 KB Output is correct
39 Correct 522 ms 884 KB Output is correct
40 Correct 472 ms 968 KB Output is correct
41 Correct 471 ms 848 KB Output is correct
42 Correct 90 ms 784 KB Output is correct
43 Correct 125 ms 784 KB Output is correct
44 Correct 171 ms 660 KB Output is correct
45 Correct 175 ms 728 KB Output is correct
46 Correct 403 ms 656 KB Output is correct
47 Correct 446 ms 648 KB Output is correct
48 Correct 66 ms 784 KB Output is correct
49 Correct 73 ms 800 KB Output is correct