답안 #964819

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
964819 2024-04-17T15:34:44 Z AdamGS Simurgh (IOI17_simurgh) C++17
100 / 100
335 ms 8908 KB
#include "simurgh.h"
#include<bits/stdc++.h>
using namespace std;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const int LIM=507;
vector<pair<int,int>>V[LIM];
vector<int>D;
pair<int,int>kraw[LIM*LIM];
int pre[LIM], mi[LIM], oc[LIM], jaki[LIM], drzewo[LIM*LIM], typ[LIM*LIM], F[LIM], lpre, n, m;
int fnd(int x) {
  if(F[x]==x) return x;
  return F[x]=fnd(F[x]);
}
bool uni(int a, int b) {
  if(fnd(a)==fnd(b)) return false;
  F[fnd(a)]=fnd(b);
  return true;
}
void DFS(int x, int o) {
  pre[x]=mi[x]=++lpre;
  for(auto i : V[x]) if(i.st!=o) {
    if(!pre[i.st]) {
      oc[i.st]=x;
      jaki[i.st]=i.nd;
      drzewo[i.nd]=1;
      DFS(i.st, x);
      mi[x]=min(mi[x], mi[i.st]);
    } else mi[x]=min(mi[x], pre[i.st]);
  }
  if(x && mi[x]==pre[x]) typ[jaki[x]]=1;
}
int cnt(vector<int>P) {
  rep(i, n) F[i]=i;
  for(auto i : P) uni(kraw[i].st, kraw[i].nd);
  int sum=0;
  for(auto i : D) if(uni(kraw[i].st, kraw[i].nd)) {
    sum+=typ[i];
    P.pb(i);
  }
  return count_common_roads(P)-sum;
}
void solve(vector<int>P, int k) {
  if(!k) {
    for(auto i : P) typ[i]=0;
    return;
  }
  if(P.size()==k) {
    for(auto i : P) typ[i]=1;
    return;
  }
  int sr=(P.size()+1)/2;
  vector<int>A, B;
  rep(i, sr) A.pb(P[i]);
  for(int i=sr; i<P.size(); ++i) B.pb(P[i]);
  int x=cnt(A);
  solve(A, x);
  solve(B, k-x);
}
vector<int>find_roads(int _n, vector<int>_u, vector<int>_v) {
  n=_n; m=_u.size();
  rep(i, m) {
    kraw[i]={_u[i], _v[i]};
    if(kraw[i].st>kraw[i].nd) swap(kraw[i].st, kraw[i].nd);
    V[kraw[i].st].pb({kraw[i].nd, i});
    V[kraw[i].nd].pb({kraw[i].st, i});
    typ[i]=-1;
  }
  DFS(0, 0);
  rep(i, m) if(drzewo[i]) D.pb(i);
  int x=count_common_roads(D);
  rep(i, m) if(!drzewo[i]) {
    int a=kraw[i].st, b=kraw[i].nd;
    if(pre[a]<pre[b]) swap(a, b);
    bool ok=false;
    for(int j=a; j!=b; j=oc[j]) {
      if(typ[jaki[j]]==-1) ok=true;
    }
    if(!ok) continue;
    for(int j=a; j!=b; j=oc[j]) if(typ[jaki[j]]==-1) {
      vector<int>T=D;
      rep(l, T.size()) if(T[l]==jaki[j]) T[l]=i;
      int y=count_common_roads(T);
      if(x==y) typ[jaki[j]]=typ[i];
      else if(x==y+1) {
        typ[jaki[j]]=1;
        typ[i]=0;
      } else {
        typ[jaki[j]]=0;
        typ[i]=1;
      }
    }
    if(typ[i]==-1) {
      ok=false;
      for(int j=a; j!=b; j=oc[j]) if(typ[jaki[j]]!=-1) {
        vector<int>T=D;
        rep(l, T.size()) if(T[l]==jaki[j]) T[l]=i;
        int y=count_common_roads(T);
        typ[i]=y-x+typ[jaki[j]];
        ok=true;
        break;
      }
      if(!ok) typ[i]=0;
    }
    for(int j=a; j!=b; j=oc[j]) if(typ[jaki[j]]==-1) typ[jaki[j]]=typ[i];
  }
  rep(i, n) {
    vector<int>P;
    rep(j, m) if(typ[j]==-1 && (kraw[j].st==i || kraw[j].nd==i)) P.pb(j);
    solve(P, cnt(P));
  }
  vector<int>ans;
  rep(i, m) if(typ[i]==1) ans.pb(i);
  return ans;
}

Compilation message

simurgh.cpp: In function 'void solve(std::vector<int>, int)':
simurgh.cpp:51:14: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   51 |   if(P.size()==k) {
      |      ~~~~~~~~^~~
simurgh.cpp:58:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |   for(int i=sr; i<P.size(); ++i) B.pb(P[i]);
      |                 ~^~~~~~~~~
simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:4:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define rep(a, b) for(int a = 0; a < (b); ++a)
      |                                    ^
simurgh.cpp:85:7: note: in expansion of macro 'rep'
   85 |       rep(l, T.size()) if(T[l]==jaki[j]) T[l]=i;
      |       ^~~
simurgh.cpp:4:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define rep(a, b) for(int a = 0; a < (b); ++a)
      |                                    ^
simurgh.cpp:100:9: note: in expansion of macro 'rep'
  100 |         rep(l, T.size()) if(T[l]==jaki[j]) T[l]=i;
      |         ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2396 KB correct
2 Correct 1 ms 2508 KB correct
3 Correct 1 ms 2472 KB correct
4 Correct 1 ms 2392 KB correct
5 Correct 1 ms 2396 KB correct
6 Correct 1 ms 2396 KB correct
7 Correct 1 ms 2648 KB correct
8 Correct 1 ms 2392 KB correct
9 Correct 2 ms 2552 KB correct
10 Correct 1 ms 2396 KB correct
11 Correct 1 ms 2396 KB correct
12 Correct 1 ms 2396 KB correct
13 Correct 2 ms 2396 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2396 KB correct
2 Correct 1 ms 2508 KB correct
3 Correct 1 ms 2472 KB correct
4 Correct 1 ms 2392 KB correct
5 Correct 1 ms 2396 KB correct
6 Correct 1 ms 2396 KB correct
7 Correct 1 ms 2648 KB correct
8 Correct 1 ms 2392 KB correct
9 Correct 2 ms 2552 KB correct
10 Correct 1 ms 2396 KB correct
11 Correct 1 ms 2396 KB correct
12 Correct 1 ms 2396 KB correct
13 Correct 2 ms 2396 KB correct
14 Correct 2 ms 2396 KB correct
15 Correct 1 ms 2396 KB correct
16 Correct 2 ms 2396 KB correct
17 Correct 2 ms 2396 KB correct
18 Correct 1 ms 2396 KB correct
19 Correct 2 ms 2396 KB correct
20 Correct 1 ms 2396 KB correct
21 Correct 2 ms 2392 KB correct
22 Correct 2 ms 2392 KB correct
23 Correct 1 ms 2548 KB correct
24 Correct 1 ms 2396 KB correct
25 Correct 1 ms 2396 KB correct
26 Correct 2 ms 2396 KB correct
27 Correct 2 ms 2396 KB correct
28 Correct 1 ms 2396 KB correct
29 Correct 2 ms 2396 KB correct
30 Correct 1 ms 2396 KB correct
31 Correct 1 ms 2396 KB correct
32 Correct 1 ms 2396 KB correct
33 Correct 1 ms 2392 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2396 KB correct
2 Correct 1 ms 2508 KB correct
3 Correct 1 ms 2472 KB correct
4 Correct 1 ms 2392 KB correct
5 Correct 1 ms 2396 KB correct
6 Correct 1 ms 2396 KB correct
7 Correct 1 ms 2648 KB correct
8 Correct 1 ms 2392 KB correct
9 Correct 2 ms 2552 KB correct
10 Correct 1 ms 2396 KB correct
11 Correct 1 ms 2396 KB correct
12 Correct 1 ms 2396 KB correct
13 Correct 2 ms 2396 KB correct
14 Correct 2 ms 2396 KB correct
15 Correct 1 ms 2396 KB correct
16 Correct 2 ms 2396 KB correct
17 Correct 2 ms 2396 KB correct
18 Correct 1 ms 2396 KB correct
19 Correct 2 ms 2396 KB correct
20 Correct 1 ms 2396 KB correct
21 Correct 2 ms 2392 KB correct
22 Correct 2 ms 2392 KB correct
23 Correct 1 ms 2548 KB correct
24 Correct 1 ms 2396 KB correct
25 Correct 1 ms 2396 KB correct
26 Correct 2 ms 2396 KB correct
27 Correct 2 ms 2396 KB correct
28 Correct 1 ms 2396 KB correct
29 Correct 2 ms 2396 KB correct
30 Correct 1 ms 2396 KB correct
31 Correct 1 ms 2396 KB correct
32 Correct 1 ms 2396 KB correct
33 Correct 1 ms 2392 KB correct
34 Correct 50 ms 3928 KB correct
35 Correct 46 ms 3484 KB correct
36 Correct 34 ms 3420 KB correct
37 Correct 5 ms 2396 KB correct
38 Correct 50 ms 3924 KB correct
39 Correct 37 ms 3420 KB correct
40 Correct 32 ms 3416 KB correct
41 Correct 46 ms 3676 KB correct
42 Correct 46 ms 3924 KB correct
43 Correct 20 ms 3164 KB correct
44 Correct 20 ms 2908 KB correct
45 Correct 19 ms 3108 KB correct
46 Correct 17 ms 2908 KB correct
47 Correct 8 ms 2652 KB correct
48 Correct 2 ms 2396 KB correct
49 Correct 4 ms 2396 KB correct
50 Correct 8 ms 2652 KB correct
51 Correct 19 ms 3104 KB correct
52 Correct 17 ms 2908 KB correct
53 Correct 17 ms 2904 KB correct
54 Correct 22 ms 3164 KB correct
55 Correct 23 ms 3112 KB correct
56 Correct 24 ms 2904 KB correct
57 Correct 20 ms 2908 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB correct
2 Correct 1 ms 2392 KB correct
3 Correct 172 ms 6208 KB correct
4 Correct 307 ms 7712 KB correct
5 Correct 322 ms 7736 KB correct
6 Correct 312 ms 7736 KB correct
7 Correct 299 ms 7600 KB correct
8 Correct 291 ms 7708 KB correct
9 Correct 327 ms 7700 KB correct
10 Correct 322 ms 7744 KB correct
11 Correct 309 ms 7720 KB correct
12 Correct 308 ms 7832 KB correct
13 Correct 1 ms 2396 KB correct
14 Correct 299 ms 7700 KB correct
15 Correct 330 ms 7728 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2396 KB correct
2 Correct 1 ms 2508 KB correct
3 Correct 1 ms 2472 KB correct
4 Correct 1 ms 2392 KB correct
5 Correct 1 ms 2396 KB correct
6 Correct 1 ms 2396 KB correct
7 Correct 1 ms 2648 KB correct
8 Correct 1 ms 2392 KB correct
9 Correct 2 ms 2552 KB correct
10 Correct 1 ms 2396 KB correct
11 Correct 1 ms 2396 KB correct
12 Correct 1 ms 2396 KB correct
13 Correct 2 ms 2396 KB correct
14 Correct 2 ms 2396 KB correct
15 Correct 1 ms 2396 KB correct
16 Correct 2 ms 2396 KB correct
17 Correct 2 ms 2396 KB correct
18 Correct 1 ms 2396 KB correct
19 Correct 2 ms 2396 KB correct
20 Correct 1 ms 2396 KB correct
21 Correct 2 ms 2392 KB correct
22 Correct 2 ms 2392 KB correct
23 Correct 1 ms 2548 KB correct
24 Correct 1 ms 2396 KB correct
25 Correct 1 ms 2396 KB correct
26 Correct 2 ms 2396 KB correct
27 Correct 2 ms 2396 KB correct
28 Correct 1 ms 2396 KB correct
29 Correct 2 ms 2396 KB correct
30 Correct 1 ms 2396 KB correct
31 Correct 1 ms 2396 KB correct
32 Correct 1 ms 2396 KB correct
33 Correct 1 ms 2392 KB correct
34 Correct 50 ms 3928 KB correct
35 Correct 46 ms 3484 KB correct
36 Correct 34 ms 3420 KB correct
37 Correct 5 ms 2396 KB correct
38 Correct 50 ms 3924 KB correct
39 Correct 37 ms 3420 KB correct
40 Correct 32 ms 3416 KB correct
41 Correct 46 ms 3676 KB correct
42 Correct 46 ms 3924 KB correct
43 Correct 20 ms 3164 KB correct
44 Correct 20 ms 2908 KB correct
45 Correct 19 ms 3108 KB correct
46 Correct 17 ms 2908 KB correct
47 Correct 8 ms 2652 KB correct
48 Correct 2 ms 2396 KB correct
49 Correct 4 ms 2396 KB correct
50 Correct 8 ms 2652 KB correct
51 Correct 19 ms 3104 KB correct
52 Correct 17 ms 2908 KB correct
53 Correct 17 ms 2904 KB correct
54 Correct 22 ms 3164 KB correct
55 Correct 23 ms 3112 KB correct
56 Correct 24 ms 2904 KB correct
57 Correct 20 ms 2908 KB correct
58 Correct 1 ms 2396 KB correct
59 Correct 1 ms 2392 KB correct
60 Correct 172 ms 6208 KB correct
61 Correct 307 ms 7712 KB correct
62 Correct 322 ms 7736 KB correct
63 Correct 312 ms 7736 KB correct
64 Correct 299 ms 7600 KB correct
65 Correct 291 ms 7708 KB correct
66 Correct 327 ms 7700 KB correct
67 Correct 322 ms 7744 KB correct
68 Correct 309 ms 7720 KB correct
69 Correct 308 ms 7832 KB correct
70 Correct 1 ms 2396 KB correct
71 Correct 299 ms 7700 KB correct
72 Correct 330 ms 7728 KB correct
73 Correct 1 ms 2396 KB correct
74 Correct 311 ms 7712 KB correct
75 Correct 304 ms 8512 KB correct
76 Correct 107 ms 4696 KB correct
77 Correct 323 ms 8676 KB correct
78 Correct 323 ms 8536 KB correct
79 Correct 335 ms 8908 KB correct
80 Correct 308 ms 8536 KB correct
81 Correct 238 ms 8020 KB correct
82 Correct 300 ms 8304 KB correct
83 Correct 192 ms 5888 KB correct
84 Correct 155 ms 6744 KB correct
85 Correct 139 ms 6380 KB correct
86 Correct 96 ms 4740 KB correct
87 Correct 70 ms 4480 KB correct
88 Correct 66 ms 3800 KB correct
89 Correct 61 ms 3576 KB correct
90 Correct 47 ms 3416 KB correct
91 Correct 11 ms 2648 KB correct
92 Correct 7 ms 2396 KB correct
93 Correct 144 ms 6384 KB correct
94 Correct 110 ms 4952 KB correct
95 Correct 92 ms 4980 KB correct
96 Correct 54 ms 3672 KB correct
97 Correct 58 ms 3676 KB correct
98 Correct 77 ms 4440 KB correct
99 Correct 60 ms 3676 KB correct
100 Correct 21 ms 2648 KB correct
101 Correct 7 ms 2608 KB correct
102 Correct 144 ms 5468 KB correct
103 Correct 144 ms 5716 KB correct
104 Correct 146 ms 5508 KB correct
105 Correct 152 ms 5600 KB correct