Submission #846195

# Submission time Handle Problem Language Result Execution time Memory
846195 2023-09-07T12:21:43 Z vjudge1 KOVANICE (COI15_kovanice) C++17
0 / 100
347 ms 27076 KB
#include <bits/stdc++.h>
using namespace std;
 
#define fast ios::sync_with_stdio(0);cin.tie(0);
#define s second
#define f first
typedef long long ll;
const ll MOD = 998244353;
const ll LOGN = 20;
const ll MAXN = 3e5 + 5;

vector<vector<int>> graph, inv;
int par[MAXN], sz[MAXN], indeg[MAXN];
int dist[MAXN];
int find(int node) {
	if (node == par[node])
		return node;
	return par[node] = find(par[node]);
}

void unite(int a, int b) {
	a = find(a);
	b = find(b);
	if (a == b)
		return ;
	if (sz[b] > sz[a])
		swap(a, b);
	par[b] = a;
	sz[a] += sz[b];
}

vector<int> type;
void dfs(int node, int req) {
	node = find(node);
	if (type[node] != -1 || dist[node] + 1 != req || req == 0)
		return ;

	type[node] = req;
	for (auto u : inv[node]) {
		dfs(u, req - 1);
	}
}

void getDist(int node) {
	for (auto u : graph[node]) {
		if (dist[u] >= dist[node] + 1)
			continue;
		dist[u] = dist[node] + 1;
		getDist(u);
	}
}

vector<pair<int,int>> edge;
int main() {
	fast
	int N, M, V;
	cin >> N >> M >> V;

	graph = vector<vector<int>>(M+1, vector<int>());
	inv = vector<vector<int>>(M+1, vector<int>());
	type = vector<int>(M+1, -1);
	for (int i = 1; i <= M; i++)
		par[i] = i, sz[i] = 1;

	for (int i = 0; i < V; i++) {
		string s;
		cin >> s;
		int l = s[0] - '0';
		int r = s[2] - '0';
		if (s[1] == '=')
			unite(l, r);
		else
			edge.push_back({l, r});
	}

	for (int i = 0; i < edge.size(); i++) {
		edge[i].f = find(edge[i].f);
		edge[i].s = find(edge[i].s);
		graph[edge[i].f].push_back(edge[i].s); 
		inv[edge[i].s].push_back(edge[i].f);
		indeg[edge[i].s]++;
	}

	for (int i = 1; i <= M; i++) {
		if (i == find(i) && indeg[i] == 0) {
			dist[i] = 0;
			getDist(i);
		}
	}

	for (int i = 1; i <= M; i++) {
		if (dist[i] + 1 == N)
			dfs(i, N);
	}

	for (int i = 1; i <= M; i++) {
		if (type[find(i)] == -1)
			cout << "?" << endl;
		else
			cout << "K" << type[find(i)] << endl;
	}
}

Compilation message

kovanice.cpp: In function 'int main()':
kovanice.cpp:76:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |  for (int i = 0; i < edge.size(); i++) {
      |                  ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4444 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 222 ms 17428 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 6608 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 347 ms 27076 KB Output isn't correct
2 Halted 0 ms 0 KB -