Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
#include
#include
#include
#include
using namespace std; const int maxn = 1e5 + 10; vector
graph[maxn]; int main() { ifstream cin("milkvisits.in"); ofstream cout("milkvisits.out"); int n, m; cin >> n >> m; string s; cin >> s; for(int i = 1; i < n; i++) { int a, b; cin >> a >> b; a--; b--; graph[a].push_back(b); graph[b].push_back(a); } vector
, char>> queries; for(int i = 0; i < m; i++) { int a, b; cin >> a >> b; a--; b--; char c; cin >> c; queries.push_back(make_pair(make_pair(a, b), c)); } vector
id(n, -1); for(int i = 0; i < n; i++) { if(id[i] == -1) { queue
q; q.push(i); while(!q.empty()) { int node = q.front(); q.pop(); id[node] = i; for(int neighbour : graph[node]) { if(id[neighbour] == -1 and s[neighbour] == s[i]) { q.push(neighbour); } } } } } string res = ""; for(int i = 0; i < m; i++) { int a = queries[i].first.first; int b = queries[i].first.second; char c = queries[i].second; if(id[a] == id[b]) { if(s[a] == c) { res += "1"; } else { res += "0"; } } else { res += "1"; } } cout << res << endl; return 0; }
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)