Submission #373000

#TimeUsernameProblemLanguageResultExecution timeMemory
373000sam571128Magenta (COCI21_magenta)C++14
0 / 110
3 ms3456 KiB
#include <bits/stdc++.h> #define int long long #define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); using namespace std; const int N = 1e5+5; vector<int> adj[N]; vector<array<int,3>> adj2[105][105][2]; //0->blue, 1->red int visited[105][105][2], deg[105][105][2], losing[105][105][2], winning[105][105][2]; void dfs(int n, int m, int p){ //cout << n << " " << m << " " << p << " " << winning[n][m][p] << " " << losing[n][m][p] << "\n"; visited[n][m][p] = 1; for(auto [nn,mm,pp] : adj2[n][m][p]){ //cout << n << " " << m << " " << p << " to " << nn << " " << mm << " " << pp << " " << deg[nn][mm][pp]<< '\n'; if(!visited[nn][mm][pp]){ if(losing[n][m][p]) winning[nn][mm][pp] = 1; else if(--deg[nn][mm][pp]==0) losing[nn][mm][pp] = 1; else continue; dfs(nn,mm,pp); } } } signed main(){ fastio int n; cin >> n; if(n <= 100){ int a,b; cin >> a >> b; for(int i = 1;i < n;i++){ int u,v; string s; cin >> u >> v >> s; adj[u].push_back(v); adj[v].push_back(u); if(s=="magenta"){ for(int j = 1;j <= 100;j++){ if(j==u||j==v) continue; adj2[u][j][1].push_back({v,j,0}), deg[u][j][1]++; adj2[v][j][1].push_back({u,j,0}), deg[v][j][1]++; } for(int j = 1;j <= 100;j++){ if(j==u||j==v) continue; adj2[j][v][0].push_back({j,u,1}), deg[j][v][0]++; adj2[j][u][0].push_back({j,v,1}), deg[j][u][0]++; } }else if(s=="plava"){ //blue for(int j = 1;j <= 100;j++){ if(j==u||j==v) continue; adj2[u][j][1].push_back({v,j,0}), deg[u][j][1]++; adj2[v][j][1].push_back({u,j,0}), deg[v][j][1]++; } }else if(s=="crvena"){ for(int j = 1;j <= 100;j++){ if(j==u||j==v) continue; adj2[j][v][0].push_back({j,u,1}), deg[j][v][0]++; adj2[j][u][0].push_back({j,v,1}), deg[j][u][0]++; } } } for(int i = 1;i <= n;i++){ for(int j = 1;j <= n;j++){ if(i!=j&&adj[i].size()==1&&adj[i][0]==j){ losing[i][j][0] = 1; losing[j][i][1] = 1; } } } for(int i = 1;i <= n;i++){ for(int j = 1;j <= n;j++){ for(int k = 0;k < 2;k++){ if((winning[i][j][k]||losing[i][j][k])&&(!visited[i][j][k])){ dfs(i,j,k); } } } } cout << (winning[a][b][0] ? "Paula\n" : losing[a][b][0] ? "Marin\n" : "Magenta\n"); } }

Compilation message (stderr)

Main.cpp: In function 'void dfs(long long int, long long int, long long int)':
Main.cpp:16:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   16 |  for(auto [nn,mm,pp] : adj2[n][m][p]){
      |           ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...