Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 69e453e

Browse files
committed
Add Solution for wheresmyinternet [OpenKattis]
1 parent 271f814 commit 69e453e

File tree

3 files changed

+76
-0
lines changed

3 files changed

+76
-0
lines changed

‎OpenKattis/wheresmyinternet/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<img src="problem.png" />

‎OpenKattis/wheresmyinternet/problem.png

269 KB
Loading[フレーム]
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
2+
#include<bits/stdc++.h>
3+
#include<cstdio>
4+
#include<cstring>
5+
#include<cmath>
6+
#include<cstring>
7+
#include<chrono>
8+
#include<complex>
9+
#define endl "\n"
10+
#define ll long long int
11+
#define vi vector<int>
12+
#define vll vector<ll>
13+
#define vvi vector < vi >
14+
#define pii pair<int,int>
15+
#define pll pair<long long, long long>
16+
#define mod 1000000007
17+
#define inf 1000000000000000001;
18+
#define all(c) c.begin(),c.end()
19+
#define mp(x,y) make_pair(x,y)
20+
#define mem(a,val) memset(a,val,sizeof(a))
21+
#define eb emplace_back
22+
#define f first
23+
#define s second
24+
25+
using namespace std;
26+
27+
int arr[200005];
28+
29+
int root(int A)
30+
{
31+
if (arr[A] == A) return A;
32+
arr[A] = root(arr[A]);
33+
return arr[A];
34+
}
35+
36+
void Union(int A , int B)
37+
{
38+
int rootA = root(A);
39+
int rootB = root(B);
40+
41+
arr[rootA] = rootB;
42+
}
43+
44+
int main()
45+
{
46+
int V, E;
47+
48+
cin>>V>>E;
49+
50+
for (int i = 0; i <= V; i++)arr[i] = i;
51+
52+
int in1 , in2;
53+
54+
for (int i = 0; i < E; i++)
55+
{
56+
cin>>in1>>in2;
57+
Union(in1,in2);
58+
}
59+
60+
bool conected = true;
61+
string pr = "";
62+
for (int i = 2; i <= V; i++)
63+
{
64+
if (root(i) != root(1))
65+
{
66+
conected = false;
67+
cout<<i<<endl;
68+
}
69+
}
70+
if (conected)cout<<"Connected"<<endl;
71+
72+
73+
74+
return 0;
75+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /