제출 #428274

#제출 시각아이디문제언어결과실행 시간메모리
428274faresbasbsSimurgh (IOI17_simurgh)C++14
0 / 100
5 ms6220 KiB
#include <bits/stdc++.h> #include "simurgh.h" using namespace std; vector<pair<int,int>> edges,graph[501],graph2[501*501]; int n,q,pre,h[501],par[501],par2[501]; bool seen[501],sg[501],seen2[501*501]; vector<int> gp[501]; set<int> used,asked; vector<int> tp[2]; void dfs3(int curr){ sg[curr] = 1; for(auto i : gp[curr]){ if(sg[i]){ continue; } dfs3(i); } } int c(){ if(used.size() != n-1){ return -1; } for(int i = 0 ; i < n ; i += 1){ gp[i].clear(); } memset(sg,0,sizeof sg); for(auto i : used){ gp[edges[i].first].push_back(edges[i].second); gp[edges[i].second].push_back(edges[i].first); } dfs3(0); for(int i = 0 ; i < n ; i += 1){ if(!sg[i]){ return -1; } } q++; vector<int> v; for(auto i : used){ v.push_back(i); } return count_common_roads(v); } void dfs(int curr){ seen[curr] = 1; for(auto i : graph[curr]){ if(seen[i.first]){ continue; } h[i.first] = h[curr]+1; used.insert(i.second); par[i.first] = curr , par2[i.first] = i.second; dfs(i.first); } } void ask(int a , int b){ if(asked.count(b) && asked.count(a)){ return ; } used.erase(a),used.insert(b); int val = c(); // for(auto i : used){ // cout << i << " "; // }cout << endl; // cout << val << endl; if(pre == val){ // cout << a << " " << b << " " << 0 << endl; graph2[a].push_back({b,0}); graph2[b].push_back({a,0}); }else{ // cout << a << " " << b << " " << 1 << endl; graph2[a].push_back({b,1}); graph2[b].push_back({a,1}); } used.erase(b),used.insert(a); asked.insert(a),asked.insert(b); } void dfs2(int curr , int val){ if(used.count(curr)){ used.erase(curr); } // cout << curr << endl; seen2[curr] = 1; tp[val].push_back(curr); for(auto i : graph2[curr]){ if(seen2[i.first]){ continue; } dfs2(i.first,val^i.second); } } vector<int> find_roads(int N , vector<int> from , vector<int> to){ n = N; for(int i = 0 ; i < from.size() ; i += 1){ edges.push_back({from[i],to[i]}); int a = from[i] , b = to[i]; graph[a].push_back({b,i}),graph[b].push_back({a,i}); } dfs(0); pre = c(); for(int i = 0 ; i < from.size() ; i += 1){ if(used.count(i)){ continue; } int a = from[i] , b = to[i]; if(h[a] < h[b]){ swap(a,b); } ask(par2[a],i); a = par[a]; if(h[a] < h[b]){ swap(a,b); } while(h[a] > h[b]){ ask(par2[a],i); a = par[a]; } while(a != b){ ask(par2[a],i),ask(par2[b],i); a = par[a] , b = par[b]; } } vector<int> v; for(auto i : used){ v.push_back(i); } for(int i = 0 ; i < from.size() ; i += 1){ if(seen2[i] || !asked.count(i)){ continue; } // cout << "start " << i << endl; // for(auto j : used){ // cout << j << " "; // }cout << endl; tp[0].clear(),tp[1].clear(); dfs2(i,0); for(auto j : tp[0]){ used.insert(j); } int val1 = c(); for(auto j : tp[0]){ used.erase(j); } for(auto j : tp[1]){ used.insert(j); } int val2 = c(); if(val2 > val1){ continue; } for(auto j : tp[1]){ used.erase(j); } for(auto j : tp[0]){ used.insert(j); } } v.clear(); for(auto i : used){ // cout << i << " "; v.push_back(i); } // cout << endl; /*if(c() != n-1){ cout << n << " " << from.size() << endl; for(int i = 0 ; i < from.size() ; i += 1){ cout << from[i] << " " << to[i] << endl; } }*/ return v; }

컴파일 시 표준 에러 (stderr) 메시지

simurgh.cpp: In function 'int c()':
simurgh.cpp:22:17: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   22 |  if(used.size() != n-1){
      |     ~~~~~~~~~~~~^~~~~~
simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:100:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  100 |  for(int i = 0 ; i < from.size() ; i += 1){
      |                  ~~^~~~~~~~~~~~~
simurgh.cpp:107:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  107 |  for(int i = 0 ; i < from.size() ; i += 1){
      |                  ~~^~~~~~~~~~~~~
simurgh.cpp:133:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  133 |  for(int i = 0 ; i < from.size() ; i += 1){
      |                  ~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...