Submission #159691

# Submission time Handle Problem Language Result Execution time Memory
159691 2019-10-24T01:05:42 Z socho Zamjena (COCI18_zamjena) C++14
70 / 70
326 ms 16348 KB
#include "bits/stdc++.h"
using namespace std;

map<string, vector<string> > adj;
map<string, bool> vis;

bool isn(string s) {
	char x = s[0];
	if (x >= '0' && x <= '9') return true;
	return false;
}

int dfsw(string s, string last) {
	if (vis[s]) return 0;
	int count = isn(s);
	vis[s] = true;
	// cout << "dfs: " << s << endl;
	for (int i=0; i<adj[s].size(); i++) {
		string other = adj[s][i];
		// cout << " > " << other << endl;
		if (other == last) continue;
		if (other == s) continue;
		if (vis[other]) continue;
		count += dfsw(other, s);
	}
	return count;
}

int main() {
	
	int n;
	cin >> n;
	string a1[n], a2[n];
	for (int i=0; i<n; i++) cin >> a1[i];
	for (int i=0; i<n; i++) cin >> a2[i];
	
	for (int i=0; i<n; i++) {
		string a = a1[i], b = a2[i];
		if (a == b) continue;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	
	for (int i=0; i<n; i++) {
		string a = a1[i];
		if (!vis[a]) {
			int re = dfsw(a, "");
			// cout << "RES: " << a << ' ' << re << endl;
			if (re > 1) {
				cout << "NE" << endl;
				exit(0);
			}
		}
	}
	cout << "DA" << endl;
	exit(0);
   
}

Compilation message

zamjena.cpp: In function 'int dfsw(std::__cxx11::string, std::__cxx11::string)':
zamjena.cpp:18:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i=0; i<adj[s].size(); i++) {
                ~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 632 KB Output is correct
2 Correct 5 ms 512 KB Output is correct
3 Correct 8 ms 1016 KB Output is correct
4 Correct 10 ms 1216 KB Output is correct
5 Correct 13 ms 1272 KB Output is correct
6 Correct 11 ms 1144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 40 ms 3320 KB Output is correct
2 Correct 86 ms 5736 KB Output is correct
3 Correct 76 ms 7560 KB Output is correct
4 Correct 121 ms 10108 KB Output is correct
5 Correct 326 ms 16348 KB Output is correct
6 Correct 209 ms 12152 KB Output is correct