Submission #1084189

# Submission time Handle Problem Language Result Execution time Memory
1084189 2024-09-05T14:57:12 Z vjudge1 KOVANICE (COI15_kovanice) C++17
50 / 100
378 ms 32848 KB
#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;
}

int odg[300001];
bool visited[300001];
vector<vector<int> > v(1000000);

void dfs(int p)
{
    visited[p]=true;
    for (int i=0;i<v[p].size();i++)
    {
        int sosed = v[p][i];
        if (visited[sosed]==false)
        {
            visited[sosed]=true;
            odg[sosed] = odg[p];
            dfs(sosed);
        }
    }
}

int main()
{
    int n,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);
        //cout<<"epa "<<x <<" "<<z<<" "<<y<<endl;

        if (z)
        {
            odg[x]=1;
            odg[y]=2;
        }
        else{
            v[x].push_back(y);
            v[y].push_back(x);
        }
    }

    for (int i=1;i<=m;i++)
        if (odg[i]>0 && visited[i]==false) dfs(i);

    for (int i=1;i<=m;i++)
    {
        if (odg[i]==0) cout<<"?\n";
        else cout<<"K"<<odg[i]<<endl;
    }

    return 0;
}

Compilation message

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 dfs(int)':
kovanice.cpp:45:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |     for (int i=0;i<v[p].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 time Memory Grader output
1 Correct 14 ms 23896 KB Output is correct
2 Correct 14 ms 23900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 163 ms 28128 KB Output is correct
2 Correct 172 ms 28500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 30 ms 24412 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 378 ms 32848 KB Output isn't correct
2 Halted 0 ms 0 KB -