답안 #206555

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
206555 2020-03-04T00:58:24 Z wiwiho Checker (COCI19_checker) C++14
110 / 110
471 ms 51828 KB
//#define NDEBUG

#include <bits/stdc++.h>
#include <bits/extc++.h>

#define StarBurstStream ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define iter(a) a.begin(), a.end()
#define riter(a) a.rbegin(), a.rend()
#define lsort(a) sort(iter(a))
#define gsort(a) sort(riter(a))
#define mp(a, b) make_pair(a, b)
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define pf(a) push_front(a)
#define pob pop_back()
#define pof pop_front()
#define F first
#define S second
#define printv(a, b) {bool pvaspace=false; \
for(auto pva : a){ \
    if(pvaspace) b << " "; pvaspace=true;\
    b << pva;\
}\
b << "\n";}
#define pii pair<int, int>
#define pll pair<ll, ll>
#define tiii tuple<int, int, int>
#define mt make_tuple
#define gt(t, i) get<i>(t)
#define iceil(a, b) ((a) / (b) + !!((a) % (b)))

//#define TEST

typedef long long ll;
typedef unsigned long long ull;

using namespace std;
using namespace __gnu_pbds;

const ll MOD = 1000000007;
const ll MAX = 2147483647;

template<typename A, typename B>
ostream& operator<<(ostream& o, pair<A, B> p){
    return o << '(' << p.F << ',' << p.S << ')';
}


int main(){
    StarBurstStream

    string nos = "neispravna triangulacija\n";
    string nop = "neispravno bojenje\n";
    string isp = "tocno\n";

    int T;
    cin >> T;

    int n;
    cin >> n;

    string s;
    cin >> s;

    vector<map<int, int>> g(n + 1);

    vector<int> deg(n + 1);
    for(int i = 1; i <= n; i++){
        int j = i + 1 > n ? 1 : i + 1;
        g[i][j] = s[i - 1] - '0';
        g[j][i] = s[i - 1] - '0';
        deg[i]++;
        deg[j]++;
    }

    for(int i = 0; i < n - 3; i ++){
        int u, v, c;
        cin >> u >> v >> c;
        if(g[u].find(v) != g[u].end()) return cout << nos, 0;
        deg[u]++; deg[v]++;
        g[u][v] = c;
        g[v][u] = c;
    }

    queue<int> q;
    vector<bool> no(n + 1);
    int cnt = 0;

    for(int i = 1; i <= n; i++) if(deg[i] == 2) q.push(i);

    int ans = 2;
    while(!q.empty()){
//        cerr << "test\n";
        if(cnt == n - 2) break;
        int now = q.front();
//        cerr << now << "\n";
        q.pop();
        no[now] = true;

        if(deg[now] != 2){
            ans = 0;
            break;
        }

        vector<int> v;
        for(pii i : g[now]){
//            cerr << "test " << i << "\n";
            if(!no[i.F]) v.eb(i.F);
        }

//        printv(v, cerr);

        if(g[v[0]].find(v[1]) == g[v[0]].end()){
            ans = 0;
            break;
        }

        if(g[v[0]][v[1]] == g[now][v[0]] || g[v[0]][v[1]] == g[now][v[1]] || g[now][v[0]] == g[now][v[1]]){
            ans = 1;
        }

        deg[v[0]]--; deg[v[1]]--;
        if(deg[v[0]] == 2) q.push(v[0]);
        if(deg[v[1]] == 2) q.push(v[1]);

        cnt++;
//        cerr << "test\n";

    }

    int tmp = 0;
    for(int i = 1; i <= n; i++) if(!no[i]) tmp++;

    if(tmp != 2) ans = 0;

    if(ans == 0) cout << nos;
    else if(ans == 1) cout << nop;
    else cout << isp;

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 504 KB Output is correct
5 Correct 6 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 504 KB Output is correct
5 Correct 6 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 7 ms 760 KB Output is correct
9 Correct 8 ms 760 KB Output is correct
10 Correct 7 ms 760 KB Output is correct
11 Correct 6 ms 760 KB Output is correct
12 Correct 7 ms 760 KB Output is correct
13 Correct 7 ms 888 KB Output is correct
14 Correct 7 ms 888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 468 ms 51732 KB Output is correct
2 Correct 463 ms 51588 KB Output is correct
3 Correct 406 ms 51588 KB Output is correct
4 Correct 312 ms 51720 KB Output is correct
5 Correct 308 ms 51588 KB Output is correct
6 Correct 431 ms 51460 KB Output is correct
7 Correct 471 ms 51460 KB Output is correct
8 Correct 380 ms 51588 KB Output is correct
9 Correct 379 ms 51460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 461 ms 51588 KB Output is correct
2 Correct 467 ms 51780 KB Output is correct
3 Correct 443 ms 51588 KB Output is correct
4 Correct 462 ms 51740 KB Output is correct
5 Correct 463 ms 51704 KB Output is correct
6 Correct 446 ms 51460 KB Output is correct
7 Correct 466 ms 51584 KB Output is correct
8 Correct 435 ms 51460 KB Output is correct
9 Correct 471 ms 51572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 504 KB Output is correct
5 Correct 6 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 7 ms 760 KB Output is correct
9 Correct 8 ms 760 KB Output is correct
10 Correct 7 ms 760 KB Output is correct
11 Correct 6 ms 760 KB Output is correct
12 Correct 7 ms 760 KB Output is correct
13 Correct 7 ms 888 KB Output is correct
14 Correct 7 ms 888 KB Output is correct
15 Correct 468 ms 51732 KB Output is correct
16 Correct 463 ms 51588 KB Output is correct
17 Correct 406 ms 51588 KB Output is correct
18 Correct 312 ms 51720 KB Output is correct
19 Correct 308 ms 51588 KB Output is correct
20 Correct 431 ms 51460 KB Output is correct
21 Correct 471 ms 51460 KB Output is correct
22 Correct 380 ms 51588 KB Output is correct
23 Correct 379 ms 51460 KB Output is correct
24 Correct 461 ms 51588 KB Output is correct
25 Correct 467 ms 51780 KB Output is correct
26 Correct 443 ms 51588 KB Output is correct
27 Correct 462 ms 51740 KB Output is correct
28 Correct 463 ms 51704 KB Output is correct
29 Correct 446 ms 51460 KB Output is correct
30 Correct 466 ms 51584 KB Output is correct
31 Correct 435 ms 51460 KB Output is correct
32 Correct 471 ms 51572 KB Output is correct
33 Correct 462 ms 51828 KB Output is correct
34 Correct 440 ms 51716 KB Output is correct
35 Correct 427 ms 51620 KB Output is correct
36 Correct 313 ms 51716 KB Output is correct
37 Correct 460 ms 51704 KB Output is correct
38 Correct 456 ms 51588 KB Output is correct
39 Correct 458 ms 51584 KB Output is correct
40 Correct 423 ms 51460 KB Output is correct
41 Correct 455 ms 51460 KB Output is correct
42 Correct 380 ms 51464 KB Output is correct
43 Correct 426 ms 51460 KB Output is correct