Submission #1084429

# Submission time Handle Problem Language Result Execution time Memory
1084429 2024-09-06T08:41:00 Z vjudge1 KOVANICE (COI15_kovanice) C++14
0 / 100
15 ms 19548 KB
#include <bits/stdc++.h>

using namespace std;
int n,m,v;
const int MAX=3*1e5+10;
int parent[MAX];
vector<int> graph[MAX];
int Find(int x)
{
    if(parent[x]==x)return x;
    else return parent[x]=Find(parent[x]);
}
void Unite(int x, int y)
{
    x=Find(x);
    y=Find(y);
    parent[y]=x;
}
int det[MAX];
void dfs(int node, int step)
{
    det[node]=step;
    for(auto x:graph[node])dfs(x,step+1);
}
int main()
{
    cin>>n>>m>>v;
    for(int i=0; i<m; i++)parent[i]=i;
    vector<pair<int,int> > op;
    bool ind[n];
    memset(det,-1,sizeof(det));
    memset(ind,false,sizeof(ind));
    for(int i=0; i<v; i++)
    {
        int a;
        cin>>a;
        char c;
        cin>>c;
        int b;
        cin>>b;
        a--;b--;
        if(c=='=')
        {
            op.push_back({a,b});
        }
        else
        {
            graph[a].push_back(b);
            ind[b]=true;
        }
    }
    for(int i=0; i<m; i++)
    {
        if(!ind[i] && graph[i].size()>0)
        {
            dfs(i,1);
            break;
        }
    }

    for(auto curr:op)
    {
        int a=Find(curr.first),b=Find(curr.second);
        if(ind[b] || graph[b].size())swap(a,b);
        Unite(a,b);
    }
    for(int i=0; i<m; i++)
    {
        int tmp=Find(i);
        if(det[tmp]==-1)cout<<"?"<<endl;
        else
        cout<<"K"<<det[tmp]<<endl;
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Runtime error 9 ms 17244 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 10 ms 18776 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 14 ms 17244 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 15 ms 19548 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -