답안 #964816

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
964816 2024-04-17T15:32:57 Z AdamGS Simurgh (IOI17_simurgh) C++17
51 / 100
294 ms 15184 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 licznik;
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);
  }
  ++licznik;
  assert(licznik<=8000);
  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);
  ++licznik;
  assert(licznik<=8000);
  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;
      ++licznik;
      assert(licznik<=8000);
      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;
        ++licznik;
        assert(licznik<=8000);
        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(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:54:14: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   54 |   if(P.size()==k) {
      |      ~~~~~~~~^~~
simurgh.cpp:61:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |   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:90:7: note: in expansion of macro 'rep'
   90 |       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:107:9: note: in expansion of macro 'rep'
  107 |         rep(l, T.size()) if(T[l]==jaki[j]) T[l]=i;
      |         ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB correct
2 Correct 1 ms 2392 KB correct
3 Correct 1 ms 2396 KB correct
4 Correct 1 ms 2396 KB correct
5 Correct 1 ms 2396 KB correct
6 Correct 1 ms 2396 KB correct
7 Correct 1 ms 2396 KB correct
8 Correct 1 ms 2396 KB correct
9 Correct 1 ms 2396 KB correct
10 Correct 1 ms 2392 KB correct
11 Correct 1 ms 2396 KB correct
12 Correct 2 ms 2396 KB correct
13 Correct 1 ms 2392 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB correct
2 Correct 1 ms 2392 KB correct
3 Correct 1 ms 2396 KB correct
4 Correct 1 ms 2396 KB correct
5 Correct 1 ms 2396 KB correct
6 Correct 1 ms 2396 KB correct
7 Correct 1 ms 2396 KB correct
8 Correct 1 ms 2396 KB correct
9 Correct 1 ms 2396 KB correct
10 Correct 1 ms 2392 KB correct
11 Correct 1 ms 2396 KB correct
12 Correct 2 ms 2396 KB correct
13 Correct 1 ms 2392 KB correct
14 Correct 2 ms 2396 KB correct
15 Correct 2 ms 2568 KB correct
16 Correct 2 ms 2396 KB correct
17 Correct 2 ms 2396 KB correct
18 Correct 2 ms 2396 KB correct
19 Correct 3 ms 2396 KB correct
20 Correct 2 ms 2396 KB correct
21 Correct 2 ms 2396 KB correct
22 Correct 2 ms 2648 KB correct
23 Correct 2 ms 2396 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 1 ms 2396 KB correct
28 Correct 1 ms 2392 KB correct
29 Correct 1 ms 2396 KB correct
30 Correct 1 ms 2396 KB correct
31 Correct 2 ms 2396 KB correct
32 Correct 2 ms 2396 KB correct
33 Correct 2 ms 2396 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB correct
2 Correct 1 ms 2392 KB correct
3 Correct 1 ms 2396 KB correct
4 Correct 1 ms 2396 KB correct
5 Correct 1 ms 2396 KB correct
6 Correct 1 ms 2396 KB correct
7 Correct 1 ms 2396 KB correct
8 Correct 1 ms 2396 KB correct
9 Correct 1 ms 2396 KB correct
10 Correct 1 ms 2392 KB correct
11 Correct 1 ms 2396 KB correct
12 Correct 2 ms 2396 KB correct
13 Correct 1 ms 2392 KB correct
14 Correct 2 ms 2396 KB correct
15 Correct 2 ms 2568 KB correct
16 Correct 2 ms 2396 KB correct
17 Correct 2 ms 2396 KB correct
18 Correct 2 ms 2396 KB correct
19 Correct 3 ms 2396 KB correct
20 Correct 2 ms 2396 KB correct
21 Correct 2 ms 2396 KB correct
22 Correct 2 ms 2648 KB correct
23 Correct 2 ms 2396 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 1 ms 2396 KB correct
28 Correct 1 ms 2392 KB correct
29 Correct 1 ms 2396 KB correct
30 Correct 1 ms 2396 KB correct
31 Correct 2 ms 2396 KB correct
32 Correct 2 ms 2396 KB correct
33 Correct 2 ms 2396 KB correct
34 Correct 50 ms 3676 KB correct
35 Correct 47 ms 3640 KB correct
36 Correct 45 ms 3456 KB correct
37 Correct 10 ms 2392 KB correct
38 Correct 55 ms 3676 KB correct
39 Correct 48 ms 3416 KB correct
40 Correct 39 ms 3420 KB correct
41 Correct 41 ms 3672 KB correct
42 Correct 47 ms 3672 KB correct
43 Correct 25 ms 3160 KB correct
44 Correct 20 ms 3044 KB correct
45 Correct 23 ms 2904 KB correct
46 Correct 20 ms 2908 KB correct
47 Correct 12 ms 2652 KB correct
48 Correct 4 ms 2396 KB correct
49 Correct 8 ms 2396 KB correct
50 Correct 12 ms 2652 KB correct
51 Correct 23 ms 2908 KB correct
52 Correct 20 ms 2908 KB correct
53 Correct 19 ms 2996 KB correct
54 Correct 29 ms 3296 KB correct
55 Correct 25 ms 3112 KB correct
56 Correct 25 ms 2904 KB correct
57 Correct 29 ms 2912 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2400 KB correct
2 Correct 1 ms 2396 KB correct
3 Correct 168 ms 6208 KB correct
4 Runtime error 294 ms 15184 KB Execution killed with signal 6
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB correct
2 Correct 1 ms 2392 KB correct
3 Correct 1 ms 2396 KB correct
4 Correct 1 ms 2396 KB correct
5 Correct 1 ms 2396 KB correct
6 Correct 1 ms 2396 KB correct
7 Correct 1 ms 2396 KB correct
8 Correct 1 ms 2396 KB correct
9 Correct 1 ms 2396 KB correct
10 Correct 1 ms 2392 KB correct
11 Correct 1 ms 2396 KB correct
12 Correct 2 ms 2396 KB correct
13 Correct 1 ms 2392 KB correct
14 Correct 2 ms 2396 KB correct
15 Correct 2 ms 2568 KB correct
16 Correct 2 ms 2396 KB correct
17 Correct 2 ms 2396 KB correct
18 Correct 2 ms 2396 KB correct
19 Correct 3 ms 2396 KB correct
20 Correct 2 ms 2396 KB correct
21 Correct 2 ms 2396 KB correct
22 Correct 2 ms 2648 KB correct
23 Correct 2 ms 2396 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 1 ms 2396 KB correct
28 Correct 1 ms 2392 KB correct
29 Correct 1 ms 2396 KB correct
30 Correct 1 ms 2396 KB correct
31 Correct 2 ms 2396 KB correct
32 Correct 2 ms 2396 KB correct
33 Correct 2 ms 2396 KB correct
34 Correct 50 ms 3676 KB correct
35 Correct 47 ms 3640 KB correct
36 Correct 45 ms 3456 KB correct
37 Correct 10 ms 2392 KB correct
38 Correct 55 ms 3676 KB correct
39 Correct 48 ms 3416 KB correct
40 Correct 39 ms 3420 KB correct
41 Correct 41 ms 3672 KB correct
42 Correct 47 ms 3672 KB correct
43 Correct 25 ms 3160 KB correct
44 Correct 20 ms 3044 KB correct
45 Correct 23 ms 2904 KB correct
46 Correct 20 ms 2908 KB correct
47 Correct 12 ms 2652 KB correct
48 Correct 4 ms 2396 KB correct
49 Correct 8 ms 2396 KB correct
50 Correct 12 ms 2652 KB correct
51 Correct 23 ms 2908 KB correct
52 Correct 20 ms 2908 KB correct
53 Correct 19 ms 2996 KB correct
54 Correct 29 ms 3296 KB correct
55 Correct 25 ms 3112 KB correct
56 Correct 25 ms 2904 KB correct
57 Correct 29 ms 2912 KB correct
58 Correct 1 ms 2400 KB correct
59 Correct 1 ms 2396 KB correct
60 Correct 168 ms 6208 KB correct
61 Runtime error 294 ms 15184 KB Execution killed with signal 6
62 Halted 0 ms 0 KB -