답안 #1013707

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1013707 2024-07-03T21:51:07 Z ThegeekKnight16 Simurgh (IOI17_simurgh) C++17
51 / 100
59 ms 2632 KB
#include <bits/stdc++.h>
#include "simurgh.h"
using namespace std;
vector<int> pai, sub;

int find(int v) {return pai[v] = (pai[v] == v ? v : find(pai[v]));}
void une(int x, int y)
{
    x = find(x); y = find(y);
    if (x == y) return;
    if (sub[x] < sub[y]) swap(x, y);
    pai[y] = x;
    sub[x] += sub[y];
}


std::vector<int> find_roads(int n, std::vector<int> u, std::vector<int> v)
{
    int M = u.size();
    vector<int> Marc(M);
    vector<int> good;
    for (int i = 0; i < M && good.size() < n-1; i++)
    {
        if (Marc[i]) continue;
        int U = u[i], V = v[i];
        pai.resize(n); sub.resize(n);
        iota(pai.begin(), pai.end(), 0);
        fill(sub.begin(), sub.end(), 1);
        vector<int> r; vector<int> poss;
        for (auto j : good) une(u[j], v[j]), r.push_back(j);
        if (find(U) == find(V)) continue;
        for (int j = 0; j < M; j++)
        {
            if (Marc[j]) continue;
            int X = u[j], Y = v[j];
            if (find(X) == find(Y)) continue;
            if ((find(X) == find(U) && find(Y) == find(V)) || (find(X) == find(V) && find(Y) == find(U)))
            {
                poss.push_back(j);
                Marc[j] = 1;
                continue;
            }
            une(X, Y); r.push_back(j);
        }
        if (poss.size() == 1) {good.push_back(i); continue;}
        vector<int> res(poss.size());
        for (int i = 0; i < poss.size(); i++)
        {
            r.push_back(poss[i]);
            res[i] = count_common_roads(r);
            r.pop_back();
        }
        int x = *max_element(res.begin(), res.end());
        for (int i = 0; i < poss.size(); i++) if (res[i] == x) good.push_back(poss[i]);
    }
    return good;
}

Compilation message

simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:22:42: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   22 |     for (int i = 0; i < M && good.size() < n-1; i++)
      |                              ~~~~~~~~~~~~^~~~~
simurgh.cpp:47:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |         for (int i = 0; i < poss.size(); i++)
      |                         ~~^~~~~~~~~~~~~
simurgh.cpp:54:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |         for (int i = 0; i < poss.size(); i++) if (res[i] == x) good.push_back(poss[i]);
      |                         ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB correct
2 Correct 0 ms 348 KB correct
3 Correct 0 ms 604 KB correct
4 Correct 0 ms 348 KB correct
5 Correct 0 ms 348 KB correct
6 Correct 0 ms 432 KB correct
7 Correct 0 ms 348 KB correct
8 Correct 0 ms 348 KB correct
9 Correct 0 ms 344 KB correct
10 Correct 0 ms 348 KB correct
11 Correct 0 ms 348 KB correct
12 Correct 0 ms 348 KB correct
13 Correct 0 ms 344 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB correct
2 Correct 0 ms 348 KB correct
3 Correct 0 ms 604 KB correct
4 Correct 0 ms 348 KB correct
5 Correct 0 ms 348 KB correct
6 Correct 0 ms 432 KB correct
7 Correct 0 ms 348 KB correct
8 Correct 0 ms 348 KB correct
9 Correct 0 ms 344 KB correct
10 Correct 0 ms 348 KB correct
11 Correct 0 ms 348 KB correct
12 Correct 0 ms 348 KB correct
13 Correct 0 ms 344 KB correct
14 Correct 1 ms 344 KB correct
15 Correct 1 ms 440 KB correct
16 Correct 1 ms 348 KB correct
17 Correct 1 ms 348 KB correct
18 Correct 0 ms 348 KB correct
19 Correct 1 ms 348 KB correct
20 Correct 1 ms 348 KB correct
21 Correct 1 ms 604 KB correct
22 Correct 1 ms 348 KB correct
23 Correct 1 ms 348 KB correct
24 Correct 1 ms 344 KB correct
25 Correct 0 ms 348 KB correct
26 Correct 1 ms 348 KB correct
27 Correct 1 ms 348 KB correct
28 Correct 0 ms 348 KB correct
29 Correct 0 ms 348 KB correct
30 Correct 1 ms 348 KB correct
31 Correct 0 ms 348 KB correct
32 Correct 1 ms 348 KB correct
33 Correct 1 ms 348 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB correct
2 Correct 0 ms 348 KB correct
3 Correct 0 ms 604 KB correct
4 Correct 0 ms 348 KB correct
5 Correct 0 ms 348 KB correct
6 Correct 0 ms 432 KB correct
7 Correct 0 ms 348 KB correct
8 Correct 0 ms 348 KB correct
9 Correct 0 ms 344 KB correct
10 Correct 0 ms 348 KB correct
11 Correct 0 ms 348 KB correct
12 Correct 0 ms 348 KB correct
13 Correct 0 ms 344 KB correct
14 Correct 1 ms 344 KB correct
15 Correct 1 ms 440 KB correct
16 Correct 1 ms 348 KB correct
17 Correct 1 ms 348 KB correct
18 Correct 0 ms 348 KB correct
19 Correct 1 ms 348 KB correct
20 Correct 1 ms 348 KB correct
21 Correct 1 ms 604 KB correct
22 Correct 1 ms 348 KB correct
23 Correct 1 ms 348 KB correct
24 Correct 1 ms 344 KB correct
25 Correct 0 ms 348 KB correct
26 Correct 1 ms 348 KB correct
27 Correct 1 ms 348 KB correct
28 Correct 0 ms 348 KB correct
29 Correct 0 ms 348 KB correct
30 Correct 1 ms 348 KB correct
31 Correct 0 ms 348 KB correct
32 Correct 1 ms 348 KB correct
33 Correct 1 ms 348 KB correct
34 Correct 59 ms 1296 KB correct
35 Correct 52 ms 1260 KB correct
36 Correct 40 ms 860 KB correct
37 Correct 3 ms 344 KB correct
38 Correct 53 ms 1284 KB correct
39 Correct 44 ms 1112 KB correct
40 Correct 36 ms 860 KB correct
41 Correct 23 ms 1204 KB correct
42 Correct 57 ms 1260 KB correct
43 Correct 33 ms 856 KB correct
44 Correct 28 ms 600 KB correct
45 Correct 32 ms 600 KB correct
46 Correct 24 ms 600 KB correct
47 Correct 13 ms 344 KB correct
48 Correct 2 ms 600 KB correct
49 Correct 4 ms 348 KB correct
50 Correct 11 ms 344 KB correct
51 Correct 31 ms 604 KB correct
52 Correct 29 ms 604 KB correct
53 Correct 26 ms 600 KB correct
54 Correct 42 ms 860 KB correct
55 Correct 36 ms 860 KB correct
56 Correct 32 ms 840 KB correct
57 Correct 35 ms 860 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB correct
2 Correct 0 ms 348 KB correct
3 Incorrect 55 ms 2632 KB WA in grader: NO
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB correct
2 Correct 0 ms 348 KB correct
3 Correct 0 ms 604 KB correct
4 Correct 0 ms 348 KB correct
5 Correct 0 ms 348 KB correct
6 Correct 0 ms 432 KB correct
7 Correct 0 ms 348 KB correct
8 Correct 0 ms 348 KB correct
9 Correct 0 ms 344 KB correct
10 Correct 0 ms 348 KB correct
11 Correct 0 ms 348 KB correct
12 Correct 0 ms 348 KB correct
13 Correct 0 ms 344 KB correct
14 Correct 1 ms 344 KB correct
15 Correct 1 ms 440 KB correct
16 Correct 1 ms 348 KB correct
17 Correct 1 ms 348 KB correct
18 Correct 0 ms 348 KB correct
19 Correct 1 ms 348 KB correct
20 Correct 1 ms 348 KB correct
21 Correct 1 ms 604 KB correct
22 Correct 1 ms 348 KB correct
23 Correct 1 ms 348 KB correct
24 Correct 1 ms 344 KB correct
25 Correct 0 ms 348 KB correct
26 Correct 1 ms 348 KB correct
27 Correct 1 ms 348 KB correct
28 Correct 0 ms 348 KB correct
29 Correct 0 ms 348 KB correct
30 Correct 1 ms 348 KB correct
31 Correct 0 ms 348 KB correct
32 Correct 1 ms 348 KB correct
33 Correct 1 ms 348 KB correct
34 Correct 59 ms 1296 KB correct
35 Correct 52 ms 1260 KB correct
36 Correct 40 ms 860 KB correct
37 Correct 3 ms 344 KB correct
38 Correct 53 ms 1284 KB correct
39 Correct 44 ms 1112 KB correct
40 Correct 36 ms 860 KB correct
41 Correct 23 ms 1204 KB correct
42 Correct 57 ms 1260 KB correct
43 Correct 33 ms 856 KB correct
44 Correct 28 ms 600 KB correct
45 Correct 32 ms 600 KB correct
46 Correct 24 ms 600 KB correct
47 Correct 13 ms 344 KB correct
48 Correct 2 ms 600 KB correct
49 Correct 4 ms 348 KB correct
50 Correct 11 ms 344 KB correct
51 Correct 31 ms 604 KB correct
52 Correct 29 ms 604 KB correct
53 Correct 26 ms 600 KB correct
54 Correct 42 ms 860 KB correct
55 Correct 36 ms 860 KB correct
56 Correct 32 ms 840 KB correct
57 Correct 35 ms 860 KB correct
58 Correct 1 ms 348 KB correct
59 Correct 0 ms 348 KB correct
60 Incorrect 55 ms 2632 KB WA in grader: NO
61 Halted 0 ms 0 KB -