The map is here - https://en.wikipedia.org/wiki/Sino-Soviet_split#/media/File:Sino-Soviet_split_1980.svg showing North Korea and Yugoslavia as the only Communist countries in the Cold War era not aligned with either the USSR or with Communist China. I am mostly interested in North Korea's situation for this question being but answers about Yugoslavia are also welcome.
The DPRK's diplomatic position in the Communist bloc after the Korean War was rather unusual. On one hand, the DPRK's ideological philosophy of Juche, first proposed in 1955 and expanded in various speeches by Kim Ill-Sung seemingly orientated the DPRK into ideological alignment with Mao's notions of a people's revolution. But at the same time, Juche's rigid adherence to national independence also sent a clear signal to Beijing that Pyongyang would not be a mere satellite. Throughout the 1960s, the DPRK sought to actively court various radical and left-wing movements throughout both the developing world and even in the West such as the Mexican Movimiento de Acción Revolucionaria, some of whose members received training in the DPRK. But even throughout the Thaw and Detente, when the USSR moved to a much more conciliatory tone with the West, Kim was always careful to avoid making a break with Moscow. The DPRK's domestic and international policies isolated it to an extent from most global contacts, but this isolation gave it a degree of heft within the socialist bloc. Neither the PRC nor the USSR would risk an open break with a troublesome DPRK less the other one take advantage of it in the Sino-Soviet split.
This strategy of playing both sides off the other was clear in 1961 when the DPRK negotiated near-simultaneous treaties with both the USSR and the PRC. DPRK negotiators for a Treaty of Friendship, Cooperation, and Mutual Assistance with Moscow neglected to tell their Soviet hosts that there were concurrently conducting negotiations with Beijing for a mutual defense pact. When Kim arrived in Moscow to sign the Treaty in July, his negotiators had already ironed out the Defense Treaty in June. Kim signed the Soviet treaty in 6 July and the Chinese treaty on 11 July, giving either benefactor little time to react.
Timing helped Kim get away with this type of double-dealing. The Park military coup in the ROK in May 1961 offered up the possibility of instability on the peninsula. This uncertainty stoked fears of a renewed Korean War, which the DPRK's media certainly stoked, but that also apprehension that the DPRK could unite the peninsula if the Park coup failed. Rejecting the DPRK for its diplomatic behavior meant that either side could be locked out of a future Korea.
The Sino-Soviet split magnified these uncertainties. The DPRK's behavior would have been problematic before the Sino-Soviet split, and in 1956 there was an abortive joint Soviet-Chinese attempt to ouster Kim from power. But as the Split solidified by the late 1950s and early 1960s, Kim found he had leverage so long as he did not push for an open break with either benefactor. DPRK's behavior was often vexing for both Moscow and Beijing, but the fear of what the other capitalizing on the abandonment of a socialist brother surrounded by the forces of capitalism overshadowed their irritation with Kim. For his part, the 1956 coup impressed upon Kim the desirability to extract as much economic and military concessions from both benefactors while not giving up any of his independence. Additionally, the DPRK could also take advantage of interbloc tensions within the Warsaw Pact states, many of whom saw engagement with Pyongyang as a way to stake out a degree of independence vis-a-vis the USSR. As long as the DPRK's actions never went completely over the line, then it could gain a degree of strength and concessions from the rest of the communist world.
This is not to say that the DPRK did not pay a price for its actions or its strident tone. Diplomatic archives from the Warsaw Pact states show that during the escalating Vietnam War, many in Moscow were disgruntled with the DPRK's radical line. A 1969 report from Hungarian DPRK with the Soviet Foreign Ministry noted that the Soviets:
They also highlighted the dangerous and unacceptable nature of that Korean view which declared that American imperialism should be dismembered "limb from limb,"a process that would be carried out by the small countries, and therefore there should be even more Vietnams, etc.
Incidents like the attack on the Pueblo Incident further alienated Moscow and led to a curtailment of military aid, as the Soviet ambassador noted in a report to Moscow that DPRK aggression seemed to be directly tied to these aggressive actions of the DPRK. Even worse for the DPRK was the rapprochement between the US and both the PRC and USSR. Not only did Detente threaten to undermine the gravity of the Sino-Soviet split (never fully achieved), but it also meant Pyongyang's militant line was out of step with the diplomatic tone set by its two patrons.
The result was that the 1970s were a period of tactical maneuvering by the DPRK to avoid a full break with either partner. Not coincidentally, the 1970s was the period where the DPRK sought most actively to cultivate relations with the developing world and promote Juche as a developmental model as a third way between the sclerotic socialism of the USSR and the extremism of Maoism. But the Third World was no substitute for a Great Power, and the DPRK gradually began to lean towards the USSR as the PRC proved less than enthusiastic. As a part of a larger attempt to mend fences in East Asia, the Gorbachev regime in the 1980s sought to mollify DPRK intransigence over issues like diplomatic recognition of the ROK through increases in aid. Soviet military aid to the DPRK received a fivefold increase in this decade and in 1985, the USSR agreed to build a nuclear reactor, which expanded the existing nuclear plant in the DPRK. The price for this support was Moscow pressured the DPRK to a more realistic line about regional and global affairs. The DPRK for example, signed the Nuclear Non-proliferation Treaty in 1985 and likewise did not put undue attacks on the Eastern bloc's participation in the Seoul Olympics in 1988.
This soft- and hard-pressure could only go so far though. Kim's reaction to the formal recognition of the USSR of the ROK in 1989/1990 prompted a major diplomatic row between Moscow and Pyongyang, which never fully recovered during the lifespan of the USSR. Juche and diplomatic isolation meant that burning diplomatic bridges carried little immediate consequences for the DPRK and the expansion of its nuclear plant in the 1980s allowed it to pursue nuclear weapons as a further guarantor of independence in the 1990s. As with the DPRK's diplomatic strategy in the Cold War, Pyongyang relies upon uncertainty about its ultimate goals and capitalizes on the fear that not dealing with an apparently unstable, tiny regime is greater than abandoning it to its fate.
Sources
Armstrong, Charles K. Tyranny of the Weak: North Korea and the World, 1950-1992. Ithaca: Cornell University Press, 2013.
Hasegawa, Tsuyoshi. The Cold War in East Asia, 1945-1991 Washington, D.C. and Stanford: Woodrow Wilson Center Press and Stanford University Press, 2011 .
Radchenko, Sergey. Unwanted Visionaries: The Soviet Failure in Asia at the End of the Cold War. Oxford: Oxford University Press, 2014.
Szalontai, Balázs. "In the Shadow of Vietnam: A New Look at North Korea's Militant Strategy, 1962–1970." Journal of Cold War Studies 14, no. 4 (2012): 122-166.