답안 #1025561

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1025561 2024-07-17T07:01:54 Z huutuan Simurgh (IOI17_simurgh) C++14
51 / 100
149 ms 2908 KB
#include "simurgh.h"

#include <bits/stdc++.h>

using namespace std;

struct DSU{
   vector<int> lab;
   void init(int n){
      lab.assign(n, -1);
   }
   int find_set(int u){
      return lab[u]<0?u:lab[u]=find_set(lab[u]);
   }
   bool check(int u, int v){
      return find_set(u)==find_set(v);
   }
   void union_sets(int u, int v){
      u=find_set(u); v=find_set(v);
      if (u!=v){
         if (lab[u]>lab[v]) swap(u, v);
         lab[u]+=lab[v];
         lab[v]=u;
      }
   }
};

int query(vector<int> &v, int x){
   v.push_back(x);
   int ans=count_common_roads(v);
   v.pop_back();
   return ans;
}

vector<int> find_roads(int n, vector<int> u, vector<int> v) {
   int m=u.size();
   int cnt=0;
   vector<int> check(m, -1);
   for (int i=0; i<m; ++i) if (check[i]==-1){
      DSU dsu1, dsu2;
      dsu1.init(n); dsu2.init(n);
      vector<int> id;
      dsu1.union_sets(u[i], v[i]);
      for (int j=0; j<m; ++j) if (i!=j){
         if (!dsu1.check(u[j], v[j])){
            dsu1.union_sets(u[j], v[j]);
            dsu2.union_sets(u[j], v[j]);
            id.push_back(j);
         }
      }
      int val=query(id, i);
      int val0=-1;
      for (int j=0; j<m; ++j) if (i!=j){
         if (!dsu2.check(u[j], v[j])){
            if (check[j]!=-1 && val0==-1){
               val0=query(id, j)-check[j];
            }
         }
      }
      if (val0!=-1){
         check[i]=val-val0;
         for (int j=0; j<m; ++j) if (i!=j){
            if (!dsu2.check(u[j], v[j])){
               if (check[j]==-1){
                  check[j]=query(id, j)-val0;
               }
            }
         }
      }else{
         val0=val;
         vector<int> vv(m);
         for (int j=0; j<m; ++j) if (i!=j){
            if (!dsu2.check(u[j], v[j])){
               vv[j]=query(id, j);
               val0=max(val0, vv[j]);
            }
         }
         --val0;
         check[i]=val-val0;
         for (int j=0; j<m; ++j) if (i!=j){
            if (!dsu2.check(u[j], v[j])){
               check[j]=vv[j]-val0;
            }
         }
      }
   }
   vector<int> ans;
   for (int i=0; i<m; ++i) if (check[i]) ans.push_back(i);
   return ans;
}

Compilation message

simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:37:8: warning: unused variable 'cnt' [-Wunused-variable]
   37 |    int cnt=0;
      |        ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB correct
2 Correct 0 ms 348 KB correct
3 Correct 0 ms 348 KB correct
4 Correct 1 ms 344 KB correct
5 Correct 0 ms 348 KB correct
6 Correct 0 ms 348 KB correct
7 Correct 0 ms 348 KB correct
8 Correct 0 ms 432 KB correct
9 Correct 0 ms 348 KB correct
10 Correct 0 ms 348 KB correct
11 Correct 0 ms 348 KB correct
12 Correct 1 ms 596 KB correct
13 Correct 0 ms 348 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB correct
2 Correct 0 ms 348 KB correct
3 Correct 0 ms 348 KB correct
4 Correct 1 ms 344 KB correct
5 Correct 0 ms 348 KB correct
6 Correct 0 ms 348 KB correct
7 Correct 0 ms 348 KB correct
8 Correct 0 ms 432 KB correct
9 Correct 0 ms 348 KB correct
10 Correct 0 ms 348 KB correct
11 Correct 0 ms 348 KB correct
12 Correct 1 ms 596 KB correct
13 Correct 0 ms 348 KB correct
14 Correct 2 ms 348 KB correct
15 Correct 2 ms 348 KB correct
16 Correct 2 ms 348 KB correct
17 Correct 2 ms 460 KB correct
18 Correct 1 ms 348 KB correct
19 Correct 2 ms 348 KB correct
20 Correct 1 ms 348 KB correct
21 Correct 1 ms 348 KB correct
22 Correct 1 ms 348 KB correct
23 Correct 1 ms 344 KB correct
24 Correct 1 ms 348 KB correct
25 Correct 1 ms 348 KB correct
26 Correct 1 ms 348 KB correct
27 Correct 1 ms 348 KB correct
28 Correct 1 ms 444 KB correct
29 Correct 1 ms 348 KB correct
30 Correct 1 ms 436 KB correct
31 Correct 1 ms 436 KB correct
32 Correct 2 ms 344 KB correct
33 Correct 1 ms 348 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB correct
2 Correct 0 ms 348 KB correct
3 Correct 0 ms 348 KB correct
4 Correct 1 ms 344 KB correct
5 Correct 0 ms 348 KB correct
6 Correct 0 ms 348 KB correct
7 Correct 0 ms 348 KB correct
8 Correct 0 ms 432 KB correct
9 Correct 0 ms 348 KB correct
10 Correct 0 ms 348 KB correct
11 Correct 0 ms 348 KB correct
12 Correct 1 ms 596 KB correct
13 Correct 0 ms 348 KB correct
14 Correct 2 ms 348 KB correct
15 Correct 2 ms 348 KB correct
16 Correct 2 ms 348 KB correct
17 Correct 2 ms 460 KB correct
18 Correct 1 ms 348 KB correct
19 Correct 2 ms 348 KB correct
20 Correct 1 ms 348 KB correct
21 Correct 1 ms 348 KB correct
22 Correct 1 ms 348 KB correct
23 Correct 1 ms 344 KB correct
24 Correct 1 ms 348 KB correct
25 Correct 1 ms 348 KB correct
26 Correct 1 ms 348 KB correct
27 Correct 1 ms 348 KB correct
28 Correct 1 ms 444 KB correct
29 Correct 1 ms 348 KB correct
30 Correct 1 ms 436 KB correct
31 Correct 1 ms 436 KB correct
32 Correct 2 ms 344 KB correct
33 Correct 1 ms 348 KB correct
34 Correct 145 ms 1288 KB correct
35 Correct 129 ms 1112 KB correct
36 Correct 92 ms 856 KB correct
37 Correct 7 ms 472 KB correct
38 Correct 133 ms 1116 KB correct
39 Correct 115 ms 1116 KB correct
40 Correct 89 ms 860 KB correct
41 Correct 149 ms 1292 KB correct
42 Correct 132 ms 1112 KB correct
43 Correct 69 ms 860 KB correct
44 Correct 60 ms 856 KB correct
45 Correct 65 ms 860 KB correct
46 Correct 49 ms 600 KB correct
47 Correct 22 ms 348 KB correct
48 Correct 3 ms 348 KB correct
49 Correct 7 ms 476 KB correct
50 Correct 22 ms 344 KB correct
51 Correct 81 ms 856 KB correct
52 Correct 57 ms 600 KB correct
53 Correct 76 ms 600 KB correct
54 Correct 83 ms 856 KB correct
55 Correct 70 ms 860 KB correct
56 Correct 64 ms 860 KB correct
57 Correct 65 ms 860 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB correct
2 Correct 0 ms 348 KB correct
3 Incorrect 60 ms 2908 KB WA in grader: NO
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB correct
2 Correct 0 ms 348 KB correct
3 Correct 0 ms 348 KB correct
4 Correct 1 ms 344 KB correct
5 Correct 0 ms 348 KB correct
6 Correct 0 ms 348 KB correct
7 Correct 0 ms 348 KB correct
8 Correct 0 ms 432 KB correct
9 Correct 0 ms 348 KB correct
10 Correct 0 ms 348 KB correct
11 Correct 0 ms 348 KB correct
12 Correct 1 ms 596 KB correct
13 Correct 0 ms 348 KB correct
14 Correct 2 ms 348 KB correct
15 Correct 2 ms 348 KB correct
16 Correct 2 ms 348 KB correct
17 Correct 2 ms 460 KB correct
18 Correct 1 ms 348 KB correct
19 Correct 2 ms 348 KB correct
20 Correct 1 ms 348 KB correct
21 Correct 1 ms 348 KB correct
22 Correct 1 ms 348 KB correct
23 Correct 1 ms 344 KB correct
24 Correct 1 ms 348 KB correct
25 Correct 1 ms 348 KB correct
26 Correct 1 ms 348 KB correct
27 Correct 1 ms 348 KB correct
28 Correct 1 ms 444 KB correct
29 Correct 1 ms 348 KB correct
30 Correct 1 ms 436 KB correct
31 Correct 1 ms 436 KB correct
32 Correct 2 ms 344 KB correct
33 Correct 1 ms 348 KB correct
34 Correct 145 ms 1288 KB correct
35 Correct 129 ms 1112 KB correct
36 Correct 92 ms 856 KB correct
37 Correct 7 ms 472 KB correct
38 Correct 133 ms 1116 KB correct
39 Correct 115 ms 1116 KB correct
40 Correct 89 ms 860 KB correct
41 Correct 149 ms 1292 KB correct
42 Correct 132 ms 1112 KB correct
43 Correct 69 ms 860 KB correct
44 Correct 60 ms 856 KB correct
45 Correct 65 ms 860 KB correct
46 Correct 49 ms 600 KB correct
47 Correct 22 ms 348 KB correct
48 Correct 3 ms 348 KB correct
49 Correct 7 ms 476 KB correct
50 Correct 22 ms 344 KB correct
51 Correct 81 ms 856 KB correct
52 Correct 57 ms 600 KB correct
53 Correct 76 ms 600 KB correct
54 Correct 83 ms 856 KB correct
55 Correct 70 ms 860 KB correct
56 Correct 64 ms 860 KB correct
57 Correct 65 ms 860 KB correct
58 Correct 1 ms 344 KB correct
59 Correct 0 ms 348 KB correct
60 Incorrect 60 ms 2908 KB WA in grader: NO
61 Halted 0 ms 0 KB -