답안 #522685

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
522685 2022-02-05T11:42:03 Z maco1503 Ronald (COCI17_ronald) C++14
120 / 120
43 ms 15260 KB
#include <bits/stdc++.h>
#define rpd ios_base :: sync_with_stdio(0); cin.tie(0);
#define ll long long
#define fs first
#define sc second
#define pb push_back
#define mod int(1e9)+7
#define NMAX 500000 + 5
#define inf INT_MAX

using namespace std;

ifstream in(".in");
ofstream out(".out");


vector< int > g[NMAX];
int viz[NMAX];
int dfs(int nod,int ant){
    if(ant!=-1&&g[nod].size()!= g[ant].size())return 1;
    int rasp=0;
    viz[nod]=1;
    for(int vecin:g[nod]){
        if(vecin==ant || viz[vecin])continue;
        rasp= rasp|dfs(vecin,nod);
        dfs(vecin,nod);
    }
    return rasp;
}

int main()
{
    rpd;
    int n,m,q;
    cin>>n>>m;
    for(int i=1;i<=m;i++)
    {
        int a,b,c;
        cin>>a>>b;
        g[a].pb(b);
        g[b].pb(a);
    }
    int cnt=0;
    for(int i=1;i<=n;i++){
        if(!viz[i]){
            int ans =dfs(i,-1);
            cnt++;
            if(ans)cnt+=3;
        }
    }
    if(cnt<=2)cout<<"DA";
    else cout<<"NE";
    return 0;
}

/*
4 4 2
1 2 10
1 3 30
2 4 20
3 4 5
3
4
*/

Compilation message

ronald.cpp: In function 'int main()':
ronald.cpp:38:17: warning: unused variable 'c' [-Wunused-variable]
   38 |         int a,b,c;
      |                 ^
ronald.cpp:34:13: warning: unused variable 'q' [-Wunused-variable]
   34 |     int n,m,q;
      |             ^
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 11980 KB Output is correct
2 Correct 9 ms 11980 KB Output is correct
3 Correct 8 ms 11980 KB Output is correct
4 Correct 6 ms 11980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 12044 KB Output is correct
2 Correct 6 ms 11980 KB Output is correct
3 Correct 7 ms 12028 KB Output is correct
4 Correct 7 ms 11980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 11980 KB Output is correct
2 Correct 6 ms 12072 KB Output is correct
3 Correct 7 ms 11980 KB Output is correct
4 Correct 7 ms 12064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 11980 KB Output is correct
2 Correct 6 ms 11980 KB Output is correct
3 Correct 6 ms 11968 KB Output is correct
4 Correct 7 ms 11980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 11980 KB Output is correct
2 Correct 6 ms 11980 KB Output is correct
3 Correct 9 ms 11980 KB Output is correct
4 Correct 6 ms 11980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 11980 KB Output is correct
2 Correct 9 ms 11980 KB Output is correct
3 Correct 9 ms 12108 KB Output is correct
4 Correct 9 ms 12108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 12108 KB Output is correct
2 Correct 14 ms 12876 KB Output is correct
3 Correct 12 ms 12276 KB Output is correct
4 Correct 8 ms 12236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 12108 KB Output is correct
2 Correct 13 ms 12620 KB Output is correct
3 Correct 36 ms 14492 KB Output is correct
4 Correct 43 ms 15260 KB Output is correct