답안 #1113025

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1113025 2024-11-15T12:39:46 Z SalihSahin Simurgh (IOI17_simurgh) C++14
51 / 100
119 ms 3676 KB
#include <bits/stdc++.h>
#define pb push_back
#include "simurgh.h"

using namespace std;
/*
static int MAXQ = 30000;

static int n, m, q = 0;
static vector<int> u, v;
static vector<bool> goal;

static void wrong_answer() {
   printf("NO\n");
   exit(0);
}

static bool is_valid(const vector<int>& r) {
   if(int(r.size()) != n - 1)
      return false;

   for(int i = 0; i < n - 1; i++)
      if (r[i] < 0 || r[i] >= m)
         return false;

   return true;
}

static int _count_common_roads_internal(const vector<int>& r) {
   if(!is_valid(r))
      wrong_answer();

   int common = 0;
   for(int i = 0; i < n - 1; i++) {
      bool is_common = goal[r[i]];
      if (is_common)
         common++;
   }

   return common; 
}

int count_common_roads(const vector<int>& r) {
   q++;
   if(q > MAXQ)
      wrong_answer();

   return _count_common_roads_internal(r);
}
*/

const int MAXN = 5e2 + 5;
vector<int> par(MAXN);
vector<pair<int, int> > adj[MAXN];

int fnd(int a){
   if(a == par[a]) return a;
   return par[a] = fnd(par[a]);
}

void merge(int a, int b){
   a = fnd(a), b = fnd(b);
   par[b] = a;
}

vector<int> find_roads(int n, vector<int> u, vector<int> v){
   vector<int> r;
   int m = u.size();
   vector<int> ok(m);
   for(int i = 0; i < m; i++){
      adj[u[i]].pb({v[i], i});
      adj[v[i]].pb({u[i], i});
   }

   for(int i = 0; i < n; i++){
      for(int j = 0; j < n; j++){
         par[j] = j;
      }

      vector<int> ottree;
      for(int j = 0; j < n; j++){
         if(j == i) continue;
         for(auto itr: adj[j]){
            if(itr.first == i) continue;
            if(fnd(j) == fnd(itr.first)) continue;
            ottree.pb(itr.second);
            merge(j, itr.first);
         }
      }
      // diğerlerini olabildiğince mergeledik 
      // a tane grup olsun a-1 tanesini random seçip a. gruptakileri dene büyük olanları tagle sonra random birini seçip a-1. için aynı şeyi yap

      vector<pair<int, int> > edge;
      set<int> df;
      for(auto itr: adj[i]){
         edge.pb({fnd(itr.first), itr.second});
         df.insert(fnd(itr.first));
      }
      sort(edge.begin(), edge.end());

      vector<int> groups[df.size()];
      int x = *(df.begin());
      int ind = 0;
      for(auto itr: edge){
         if(itr.first != x){
            ind++;
            x = itr.first;
         }
         groups[ind].pb(itr.second);
      }

      for(int g = 0; g < df.size(); g++){
         if(groups[g].size() == 1){
            ok[groups[g][0]] = 1;
            continue;
         }

         for(int g2 = 0; g2 < df.size(); g2++){
            if(g2 == g) continue;
            ottree.pb(groups[g2][0]);
         }

         vector<pair<int, int> > vals;
         int mx = 0;
         for(auto itr: groups[g]){
            if(ok[itr] != -1){
               ottree.pb(itr);
               int cnt = count_common_roads(ottree);
               vals.pb({cnt, itr});
               mx = max(mx, cnt);
               ottree.pop_back();
            }
         }

         for(int j = 0; j < vals.size(); j++){
            if(vals[j].first == mx) ok[vals[j].second] = 1;
            else ok[vals[j].second] = -1;
         }

         for(int g2 = 0; g2 < df.size(); g2++){
            if(g2 == g) continue;
            ottree.pop_back();
         }
      }

   }

   for(int i = 0; i < m; i++){
      if(ok[i] == 1) r.pb(i);
   }

   return r;
}
/*

int main() {
   assert(2 == scanf("%d %d", &n, &m));

   u.resize(m);
   v.resize(m);

   for(int i = 0; i < m; i++)
      assert(2 == scanf("%d %d", &u[i], &v[i]));

   goal.resize(m, false);

   for(int i = 0; i < n - 1; i++) {
      int id;
      assert(1 == scanf("%d", &id));
      goal[id] = true;
   }

   vector<int> res = find_roads(n, u, v);
   for(auto itr: res){
      cout<<itr<<" ";
   }
   cout<<endl;

   if(_count_common_roads_internal(res) != n - 1)
      wrong_answer();

   printf("YES\n");

   return 0;
}*/

Compilation message

simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:112:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::set<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  112 |       for(int g = 0; g < df.size(); g++){
      |                      ~~^~~~~~~~~~~
simurgh.cpp:118:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::set<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  118 |          for(int g2 = 0; g2 < df.size(); g2++){
      |                          ~~~^~~~~~~~~~~
simurgh.cpp:135:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  135 |          for(int j = 0; j < vals.size(); j++){
      |                         ~~^~~~~~~~~~~~~
simurgh.cpp:140:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::set<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  140 |          for(int g2 = 0; g2 < df.size(); g2++){
      |                          ~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB correct
2 Correct 1 ms 336 KB correct
3 Correct 1 ms 336 KB correct
4 Correct 1 ms 336 KB correct
5 Correct 1 ms 336 KB correct
6 Correct 1 ms 336 KB correct
7 Correct 1 ms 336 KB correct
8 Correct 1 ms 336 KB correct
9 Correct 1 ms 336 KB correct
10 Correct 1 ms 336 KB correct
11 Correct 1 ms 336 KB correct
12 Correct 1 ms 504 KB correct
13 Correct 1 ms 336 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB correct
2 Correct 1 ms 336 KB correct
3 Correct 1 ms 336 KB correct
4 Correct 1 ms 336 KB correct
5 Correct 1 ms 336 KB correct
6 Correct 1 ms 336 KB correct
7 Correct 1 ms 336 KB correct
8 Correct 1 ms 336 KB correct
9 Correct 1 ms 336 KB correct
10 Correct 1 ms 336 KB correct
11 Correct 1 ms 336 KB correct
12 Correct 1 ms 504 KB correct
13 Correct 1 ms 336 KB correct
14 Correct 2 ms 336 KB correct
15 Correct 2 ms 336 KB correct
16 Correct 3 ms 524 KB correct
17 Correct 2 ms 336 KB correct
18 Correct 1 ms 336 KB correct
19 Correct 2 ms 336 KB correct
20 Correct 2 ms 336 KB correct
21 Correct 2 ms 336 KB correct
22 Correct 1 ms 336 KB correct
23 Correct 2 ms 432 KB correct
24 Correct 2 ms 336 KB correct
25 Correct 1 ms 336 KB correct
26 Correct 2 ms 336 KB correct
27 Correct 2 ms 336 KB correct
28 Correct 1 ms 336 KB correct
29 Correct 1 ms 336 KB correct
30 Correct 2 ms 336 KB correct
31 Correct 1 ms 504 KB correct
32 Correct 2 ms 336 KB correct
33 Correct 2 ms 336 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB correct
2 Correct 1 ms 336 KB correct
3 Correct 1 ms 336 KB correct
4 Correct 1 ms 336 KB correct
5 Correct 1 ms 336 KB correct
6 Correct 1 ms 336 KB correct
7 Correct 1 ms 336 KB correct
8 Correct 1 ms 336 KB correct
9 Correct 1 ms 336 KB correct
10 Correct 1 ms 336 KB correct
11 Correct 1 ms 336 KB correct
12 Correct 1 ms 504 KB correct
13 Correct 1 ms 336 KB correct
14 Correct 2 ms 336 KB correct
15 Correct 2 ms 336 KB correct
16 Correct 3 ms 524 KB correct
17 Correct 2 ms 336 KB correct
18 Correct 1 ms 336 KB correct
19 Correct 2 ms 336 KB correct
20 Correct 2 ms 336 KB correct
21 Correct 2 ms 336 KB correct
22 Correct 1 ms 336 KB correct
23 Correct 2 ms 432 KB correct
24 Correct 2 ms 336 KB correct
25 Correct 1 ms 336 KB correct
26 Correct 2 ms 336 KB correct
27 Correct 2 ms 336 KB correct
28 Correct 1 ms 336 KB correct
29 Correct 1 ms 336 KB correct
30 Correct 2 ms 336 KB correct
31 Correct 1 ms 504 KB correct
32 Correct 2 ms 336 KB correct
33 Correct 2 ms 336 KB correct
34 Correct 115 ms 1360 KB correct
35 Correct 114 ms 1760 KB correct
36 Correct 80 ms 1360 KB correct
37 Correct 7 ms 504 KB correct
38 Correct 116 ms 1784 KB correct
39 Correct 101 ms 1616 KB correct
40 Correct 76 ms 1360 KB correct
41 Correct 119 ms 1788 KB correct
42 Correct 110 ms 1616 KB correct
43 Correct 61 ms 1104 KB correct
44 Correct 48 ms 1060 KB correct
45 Correct 66 ms 1104 KB correct
46 Correct 43 ms 848 KB correct
47 Correct 20 ms 592 KB correct
48 Correct 4 ms 336 KB correct
49 Correct 8 ms 504 KB correct
50 Correct 21 ms 592 KB correct
51 Correct 56 ms 1104 KB correct
52 Correct 55 ms 848 KB correct
53 Correct 45 ms 860 KB correct
54 Correct 62 ms 1104 KB correct
55 Correct 57 ms 1104 KB correct
56 Correct 58 ms 1128 KB correct
57 Correct 61 ms 1104 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB correct
2 Correct 1 ms 336 KB correct
3 Incorrect 77 ms 3676 KB WA in grader: NO
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB correct
2 Correct 1 ms 336 KB correct
3 Correct 1 ms 336 KB correct
4 Correct 1 ms 336 KB correct
5 Correct 1 ms 336 KB correct
6 Correct 1 ms 336 KB correct
7 Correct 1 ms 336 KB correct
8 Correct 1 ms 336 KB correct
9 Correct 1 ms 336 KB correct
10 Correct 1 ms 336 KB correct
11 Correct 1 ms 336 KB correct
12 Correct 1 ms 504 KB correct
13 Correct 1 ms 336 KB correct
14 Correct 2 ms 336 KB correct
15 Correct 2 ms 336 KB correct
16 Correct 3 ms 524 KB correct
17 Correct 2 ms 336 KB correct
18 Correct 1 ms 336 KB correct
19 Correct 2 ms 336 KB correct
20 Correct 2 ms 336 KB correct
21 Correct 2 ms 336 KB correct
22 Correct 1 ms 336 KB correct
23 Correct 2 ms 432 KB correct
24 Correct 2 ms 336 KB correct
25 Correct 1 ms 336 KB correct
26 Correct 2 ms 336 KB correct
27 Correct 2 ms 336 KB correct
28 Correct 1 ms 336 KB correct
29 Correct 1 ms 336 KB correct
30 Correct 2 ms 336 KB correct
31 Correct 1 ms 504 KB correct
32 Correct 2 ms 336 KB correct
33 Correct 2 ms 336 KB correct
34 Correct 115 ms 1360 KB correct
35 Correct 114 ms 1760 KB correct
36 Correct 80 ms 1360 KB correct
37 Correct 7 ms 504 KB correct
38 Correct 116 ms 1784 KB correct
39 Correct 101 ms 1616 KB correct
40 Correct 76 ms 1360 KB correct
41 Correct 119 ms 1788 KB correct
42 Correct 110 ms 1616 KB correct
43 Correct 61 ms 1104 KB correct
44 Correct 48 ms 1060 KB correct
45 Correct 66 ms 1104 KB correct
46 Correct 43 ms 848 KB correct
47 Correct 20 ms 592 KB correct
48 Correct 4 ms 336 KB correct
49 Correct 8 ms 504 KB correct
50 Correct 21 ms 592 KB correct
51 Correct 56 ms 1104 KB correct
52 Correct 55 ms 848 KB correct
53 Correct 45 ms 860 KB correct
54 Correct 62 ms 1104 KB correct
55 Correct 57 ms 1104 KB correct
56 Correct 58 ms 1128 KB correct
57 Correct 61 ms 1104 KB correct
58 Correct 1 ms 336 KB correct
59 Correct 1 ms 336 KB correct
60 Incorrect 77 ms 3676 KB WA in grader: NO
61 Halted 0 ms 0 KB -