#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[m];
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 |
Incorrect |
5 ms |
8540 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
250 ms |
12892 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2102 ms |
10008 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2041 ms |
19176 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |