답안 #366396

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
366396 2021-02-14T06:34:52 Z faustaadp Magenta (COCI21_magenta) C++17
30 / 110
157 ms 57344 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
const int NN = 1e6 + 5;
const int mo = 1e9 + 7;
const ld eps = 1e-9;
ll n, a, b;
vector<ll> v[NN];
vector<ll> w[NN];
ll A = 0;
ll B = 0;
ll dis[4][NN];
ll rg[4];
void dfs(ll pos, ll par, ll jen, ll jar)
{
    if(jen == 2)
        rg[jen]++;
    // if(jen == 2)
        // rg[2]++;
    dis[jen][pos] = jar;
    for(ll i = 0; i < v[pos].size(); i++)
        if((v[pos][i] != par) && (w[pos][i] & jen))
            dfs(v[pos][i], pos, jen, jar + 1);
}
void dfs1(ll pos, ll par)
{
    if(dis[2][pos] < dis[1][pos])
        return ;
    rg[1]++;
    if(dis[2][pos] == 1e18)
    {
        for(ll i = 0; i < v[pos].size(); i++)
            if(dis[2][v[pos][i]] == 1e18)
                A = 1;
        for(ll i = 0; i < v[pos].size(); i++)
            if((dis[2][v[pos][i]] % 2) == (dis[1][v[pos][i]] % 2))
                A = 1;
    }
    for(ll i = 0; i < v[pos].size(); i++)
        if((v[pos][i] != par) && (w[pos][i] & 1))
            dfs1(v[pos][i], pos);
}
void dfs2(ll pos, ll par)
{
    if(dis[1][pos] <= dis[2][pos])
        return ;
    // rg[2]++;
    if(dis[1][pos] == 1e18)
    {
        for(ll i = 0; i < v[pos].size(); i++)
            if(dis[1][v[pos][i]] == 1e18)
                B = 1;
        for(ll i = 0; i < v[pos].size(); i++)
            if((dis[1][v[pos][i]] % 2) != (dis[2][v[pos][i]] % 2))
                B = 1;
    }
    for(ll i = 0; i < v[pos].size(); i++)
        if((v[pos][i] != par) && (w[pos][i] & 2))
            dfs2(v[pos][i], pos);
}
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n >> a >> b;
    for(ll i = 1; i <= n; i++)
    {
        dis[1][i] = 1e18;
        dis[2][i] = 1e18;
    }
    for(ll i = 1; i < n; i++)
    {
        ll ta, tb, tc = 3;
        string s;
        cin >> ta >> tb >> s;
        if(s == "plava")tc = 1;
        else if(s == "crvena")tc = 2;
        v[ta].pb(tb);
        w[ta].pb(tc);
        v[tb].pb(ta);
        w[tb].pb(tc);
    }
    dfs(a, a, 1, 0);
    dfs(b, b, 2, 0);
    dfs(a, a, 3, 0);
    dfs1(a, a);
    dfs2(b, b);
    // if(A == 0 && B == 0)
    // {
    //     if(dis[1][b])
    // }
    // cout << rg[1] << "  " << rg[2] << "\n";
   
    // cout << A << " " << B << " " << dis[3][b] << "@\n" << "\n";
    if(rg[1] == 1)
        cout << "Marin\n";
    else
    if(rg[2] == 1)
        cout << "Paula\n";
    else
    if(((dis[3][b] % 2 == 0) && (dis[3][b] != 1e18)) && (B == 0))
        cout << "Paula\n";
    else
    if((dis[3][b] % 2 == 1) && (A == 0))
        cout << "Marin\n";
    else
        cout << "Magenta\n";
}
    

Compilation message

Main.cpp: In function 'void dfs(ll, ll, ll, ll)':
Main.cpp:26:21: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |     for(ll i = 0; i < v[pos].size(); i++)
      |                   ~~^~~~~~~~~~~~~~~
Main.cpp: In function 'void dfs1(ll, ll)':
Main.cpp:37:25: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |         for(ll i = 0; i < v[pos].size(); i++)
      |                       ~~^~~~~~~~~~~~~~~
Main.cpp:40:25: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |         for(ll i = 0; i < v[pos].size(); i++)
      |                       ~~^~~~~~~~~~~~~~~
Main.cpp:44:21: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |     for(ll i = 0; i < v[pos].size(); i++)
      |                   ~~^~~~~~~~~~~~~~~
Main.cpp: In function 'void dfs2(ll, ll)':
Main.cpp:55:25: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |         for(ll i = 0; i < v[pos].size(); i++)
      |                       ~~^~~~~~~~~~~~~~~
Main.cpp:58:25: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |         for(ll i = 0; i < v[pos].size(); i++)
      |                       ~~^~~~~~~~~~~~~~~
Main.cpp:62:21: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |     for(ll i = 0; i < v[pos].size(); i++)
      |                   ~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 47340 KB Output is correct
2 Correct 28 ms 47340 KB Output is correct
3 Correct 28 ms 47340 KB Output is correct
4 Correct 28 ms 47340 KB Output is correct
5 Correct 28 ms 47488 KB Output is correct
6 Correct 28 ms 47340 KB Output is correct
7 Correct 28 ms 47340 KB Output is correct
8 Correct 28 ms 47340 KB Output is correct
9 Correct 27 ms 47340 KB Output is correct
10 Correct 28 ms 47340 KB Output is correct
11 Correct 28 ms 47340 KB Output is correct
12 Correct 28 ms 47340 KB Output is correct
13 Incorrect 28 ms 47340 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 154 ms 57196 KB Output is correct
2 Correct 155 ms 57324 KB Output is correct
3 Correct 153 ms 57196 KB Output is correct
4 Correct 157 ms 57324 KB Output is correct
5 Correct 152 ms 57344 KB Output is correct
6 Correct 29 ms 47340 KB Output is correct
7 Correct 28 ms 47340 KB Output is correct
8 Correct 28 ms 47468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 47340 KB Output is correct
2 Correct 28 ms 47340 KB Output is correct
3 Correct 28 ms 47340 KB Output is correct
4 Correct 28 ms 47340 KB Output is correct
5 Correct 28 ms 47488 KB Output is correct
6 Correct 28 ms 47340 KB Output is correct
7 Correct 28 ms 47340 KB Output is correct
8 Correct 28 ms 47340 KB Output is correct
9 Correct 27 ms 47340 KB Output is correct
10 Correct 28 ms 47340 KB Output is correct
11 Correct 28 ms 47340 KB Output is correct
12 Correct 28 ms 47340 KB Output is correct
13 Incorrect 28 ms 47340 KB Output isn't correct