Submission #1084222

#TimeUsernameProblemLanguageResultExecution timeMemory
1084222vjudge1KOVANICE (COI15_kovanice)C++17
50 / 100
220 ms58304 KiB
#include <bits/stdc++.h> using namespace std; int prv_broj(string s) { int x=0; for (int i=0;i<s.size();i++) { if (s[i]=='<' || s[i]=='=') return x; x = x*10 + (s[i]-'0'); } } bool znak(string s) { for (int i=0;i<s.size();i++) if (s[i]=='<') return true; else if (s[i]=='=') return false; } int vtor_broj(string s) { int p=0; while(s[p]!='<' && s[p]!='=') p++; p++; int y=0; while(p<s.size()) { y=y*10+(s[p]-'0'); p++; } return y; } vector<pair<int,int> > v; vector<vector<int> > ednakvi(1000000); vector<vector<int> > pogolemi(1000000); int pomali[300001]; int component[300001]; int c=0; void dfs1(int poz) { component[poz] = c; for (int i=0;i<ednakvi[poz].size();i++) { int sosed = ednakvi[poz][i]; if (component[sosed]==0) { component[sosed] = c; dfs1(sosed); } } } void make_components(int m) { for (int i=1;i<=m;i++) if (component[i]==0){ c++; dfs1(i); } /*for (int i=1;i<=m;i++) cout<<"component["<<i<<"]="<<component[i]<<endl;*/ } void make_vectors() { for (int i=0;i<v.size();i++) { v[i].first = component[v[i].first]; v[i].second = component[v[i].second]; } sort(v.begin(),v.end()); for (int i=0;i<v.size();i++) { int x = v[i].first; int y = v[i].second; pogolemi[x].push_back(y); pomali[y]++; } } int dp[300001],n; bool dfs2(int poz,int depth) { if (dp[poz]>0) return (depth == dp[poz]); if (pogolemi[poz].size()==0) { if (depth == n) { dp[poz] = depth; return true; } return false; } bool b = false; for (int i=0;i<pogolemi[poz].size();i++) { int sosed = pogolemi[poz][i]; b = max(b,dfs2(sosed,depth+1)); } if (b) dp[poz] = depth; return b; } void solve() { for (int i=1;i<=c;i++) { if (pomali[i]==0) { dfs2(i,1); } } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int m,k; cin>>n>>m>>k; for (int i=0;i<k;i++) { string s; cin>>s; int x = prv_broj(s); bool z = znak(s); int y = vtor_broj(s); if (z) { v.push_back({x,y}); } else{ ednakvi[x].push_back(y); ednakvi[y].push_back(x); } } make_components(m); if (n>2) { cout<<"yes\n"; return 0; } make_vectors(); if (n>2) { cout<<"yes\n"; return 0; } solve(); for (int i=1;i<=m;i++) { int x = component[i]; if (dp[x] == 0) cout<<"?\n"; else cout<< "K"<<dp[x]<<endl; } return 0; }

Compilation message (stderr)

kovanice.cpp: In function 'int prv_broj(std::string)':
kovanice.cpp:8:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 |     for (int i=0;i<s.size();i++)
      |                  ~^~~~~~~~~
kovanice.cpp: In function 'bool znak(std::string)':
kovanice.cpp:17:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |     for (int i=0;i<s.size();i++)
      |                  ~^~~~~~~~~
kovanice.cpp: In function 'int vtor_broj(std::string)':
kovanice.cpp:30:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |     while(p<s.size())
      |           ~^~~~~~~~~
kovanice.cpp: In function 'void dfs1(int)':
kovanice.cpp:48:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |     for (int i=0;i<ednakvi[poz].size();i++)
      |                  ~^~~~~~~~~~~~~~~~~~~~
kovanice.cpp: In function 'void make_vectors()':
kovanice.cpp:73:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |     for (int i=0;i<v.size();i++)
      |                  ~^~~~~~~~~
kovanice.cpp:80:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   80 |     for (int i=0;i<v.size();i++)
      |                  ~^~~~~~~~~
kovanice.cpp: In function 'bool dfs2(int, int)':
kovanice.cpp:104:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  104 |     for (int i=0;i<pogolemi[poz].size();i++)
      |                  ~^~~~~~~~~~~~~~~~~~~~~
kovanice.cpp: In function 'int prv_broj(std::string)':
kovanice.cpp:13:1: warning: control reaches end of non-void function [-Wreturn-type]
   13 | }
      | ^
kovanice.cpp: In function 'bool znak(std::string)':
kovanice.cpp:20:1: warning: control reaches end of non-void function [-Wreturn-type]
   20 | }
      | ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...